Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Can someone please help me understand what i am doing wrong, i have been at it for a week now and i cannot pass step 9

do not tell me the answer, just tell me the problem

Your code so far

const cargoManifest = {
  containerId: 1,
  destination: "Monterey, California, USA",
  weight: 831,
  unit: "lb",
  hazmat: false
};

const normalizeUnits = (manifest) => {
 const newManifest = {...manifest};

 if (newManifest.unit === "lb") {
    newManifest.weight = Number((newManifest.weight * 0.45).toFixed(2));
    newManifest.unit = "kg";

    console.log(`unit conversion made - newManifest.weight from lb to kg`);
     return newManifest;

  } else if (newManifest.unit == 'kg'){
    console.log();
     return newManifest;
  }

  return manifest
};

console.log(normalizeUnits({
  containerId: 1,
  destination: "Monterey, California, USA",
  weight: 80,
  unit: "lb",
  hazmat: true
}));

//Validate Manifest section
const validateManifest = (manifest) => {
  const newValidation = {...manifest};

newValidation.containerId = ("containerId" in newValidation && typeof newValidation.containerId === "number") ? newValidation.containerId : ("containerId" in newValidation && typeof newValidation.containerId !== "number") ? "Invalid" : "Missing";

  newValidation.destination =  ("destination" in newValidation && typeof newValidation.destination === "string") ? newValidation.destination : ("destination" in newValidation && typeof newValidation.destination !== "string") ? "Invalid" : "Missing";

  newValidation.weight = ("weight" in newValidation && typeof newValidation.weight === "number") ? newValidation.weight : ("weight" in newValidation && typeof newValidation.weight !== "number") ? "invalid" : "Missing";

  newValidation.unit = ("unit" in newValidation && typeof newValidation.unit === "string") ? newValidation.unit : ("unit" in newValidation && typeof newValidation.unit !== "string") ? "Invalid" : "Missing";

  newValidation.hazmat = ("hazmat" in newValidation && typeof newValidation.hazmat === "boolean") ? newValidation.hazmat : ("hazmat" in newValidation && typeof newValidation.hazmat !== "boolean") ? "Invalid" : "Missing";


if ("containerId" in newValidation && typeof newValidation.containerId === "number"
&& 
"destination" in newValidation && typeof newValidation.destination === "string"
&&
"weight" in newValidation && typeof newValidation.weight === "number"
&&
"unit" in newValidation && typeof newValidation.unit === "string"
&&
"hazmat" in newValidation && typeof newValidation.hazmat === "boolean") {
  return new Object();
}

    return newValidation
}; 


console.log(validateManifest({containerId: null, destination: 22, weight: "yac", unit: "lb", hazmat: true }));

Your browser information:

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

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

Hi @Mr-Yangtk,

Add console.log(newValidation) right after Line 47.
Then add console.log("in here") just before return new Object();.

Then try testing your code with this function call:

console.log(validateManifest({ containerId: -1, destination: 22, weight: NaN, unit: "pound", hazmat: false }));

This should give you a lot of information to troubleshoot your code.

Happy coding!

Edited: changed hazmat in function call to false to show you that your code returns an empty object even when there are invalid values.

I am still unable to pass the validateManifest section of the challenge, but I was able to debug most of the code due to your help. Thanks ! . I will keep on trying