Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Fail in step 21, 25, and 26. The answer seems to be correct. I’ve tried rearranging and changing things; can anyone give me some tips? thanks.

Your code so far


const normalizeUnits = manifest => {
  const newManifest = {...manifest};
  if(newManifest.unit === "lb") {
    newManifest.weight = newManifest.weight*0.45;
    newManifest.unit = "kg"
  }
  return newManifest;
}
const validateManifest = manifest => {
const newManifest = {...manifest};
const errs = {};
if(newManifest.containerId === undefined) {
  errs.containerId = "Missing";
}else if(!Number.isInteger(newManifest.containerId) || newManifest.containerId <= 0) {
  errs.containerId = "Invalid";
}
if(newManifest.destination === undefined) {
  errs.destination = "Missing";
}else if(typeof newManifest.destination !== "string" || newManifest.destination.trim() === '') {
  errs.destination = "Invalid"
}
if(newManifest.weight === undefined) {
  errs.weight = "Missing"
}else if(typeof newManifest.weight !== "number" || newManifest.weight <= 0 || Number.isNaN(newManifest.weight)) {
  errs.weight = "Invalid"
}
if(newManifest.unit === undefined) {
  errs.unit = "Missing"
}else if(newManifest.unit !== "kg" && newManifest.unit !== "lb") {
  errs.unit = "Invalid"
}
if(newManifest.hazmat === undefined) {
  errs.hazmat = "Missing" 
}else if(typeof newManifest.hazmat !== "boolean") {
  errs.hazmat = "Invalid"
}
return errs 
};
const processManifest = manifest => {
  const newManifest = {...manifest}
  const errs = validateManifest(newManifest);
  const isValid = Object.keys(errs).length === 0;
  
  if(isValid) {
    console.log(`Validation success: ${newManifest.containerId}`);
    const normalizedNewmanifest = normalizeUnits(newManifest);
    console.log(`Total weight: ${normalizedNewmanifest.weight} kg`)
  }else {
    console.log(`Validation error: ${newManifest.containerId}`);
    console.log(errs)
  }
}

console.log(processManifest({ containerId: 55, destination: "Carmel", weight: -100, unit: "lb", hazmat: false }));


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36

Challenge Information:

Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-cargo-manifest-validator/69a56b5069ca99f7317e6e19.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome back @xuannnnnnnnnnnnnnn,

Try declaring your arrow functions with let rather than const since the tests are reassigning those.

Staff is working on getting a note up about this.

Happy coding

Thanks for your guidance; the code passed. :smiling_face_with_three_hearts: