Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

getting stuck on no.16 and 1, havent used const but think thats just a testing bug, 16 not sure how else to test it, no syntax or logic failures

Your code so far

function normalizeUnits(manifest) {
  let copy = {...manifest}
  if (copy.unit === "lb") {
    let newWeight = copy.weight * 0.45;
    copy.weight = newWeight;
    copy.unit = "kg";
  } else {
    return copy;
  }
  return copy;
}

function validateManifest(manifest) {
  let errors = {};
   if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) {
   return { manifest: "Invalid input type. Must be an object." }; 
  } 
  if (!manifest.hasOwnProperty("containerId")) {
    errors.containerId = "Missing";
  }else if (manifest.containerId === null || manifest.containerId <= 0 || typeof manifest.containerId !== "number" || !Number.isInteger(manifest.containerId)) {
    errors.containerId = "Invalid";
  }
  if (!manifest.hasOwnProperty("destination")) {
  errors.destination = "Missing";
} else if (typeof manifest.destination !== "string" || manifest.destination.trim() === "") {
  errors.destination = "Invalid";
}

  if (!manifest.hasOwnProperty("weight")) {
    errors.weight = "Missing";
  } else if (
  typeof manifest.weight !== "number" || !Number.isFinite(manifest.weight) ||
  manifest.weight < 0) { 
  errors.weight = "Invalid";
}

  if (!manifest.hasOwnProperty("unit")) { 
    errors.unit = "Missing";
  } else if (
    typeof manifest.unit !== "string" ||
    !["lb", "kg"].includes(manifest.unit.toLowerCase())
  ) {
    errors.unit = "Invalid";
  }

  if (!manifest.hasOwnProperty("hazmat")) {
    errors.hazmat = "Missing";
  } else if (typeof manifest.hazmat !== "boolean") {
    errors.hazmat = "Invalid";
  }

  return errors; 

} 



console.log(validateManifest({ containerId: -6,
  destination: 123,
  weight: 0,
  unit: 'pounds',
  hazmat: true })) 

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.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

test 1 is checking 3 functions, one of which does not exist yet, so it fails

for test 16, double check the requirements, what are the valid unit and weight values? like, KG, kg, kG, are they all valid? what about a weight of 0?

In your normalizeUnits function, check where return copy; is placed. Right now it is inside the else block. When copy.unit is “lb”, the function updates the values but never returns the object, resulting in undefined. You can move return copy; to the end of the function so it always returns the modified copy.

Also check if test 16 expects a specific conversion factor or rounding for normalizeUnits, or if it tests validateManifest with edge cases like missing properties or non-integer IDs.