Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

This passes all tests but 21. I have no idea what isn’t working, could anyone give me a hint?

Your code so far

const normalizeUnits = manifest => {
  const copy = { ...manifest }
  if (copy.unit === "lb") {
    copy.weight *= 0.45;
    copy.unit = "kg";
  }
  return copy;
};

const validateManifest = manifest => {
  const validate = {};
  //containerId
  if (!Object.hasOwn(manifest, "containerId")) { validate.containerId = "Missing"; }
  else if (!Number.isInteger(manifest.containerId) || manifest.containerId <= 0) {
    validate.containerId = "Invalid";
  }

  //destination
  if (!Object.hasOwn(manifest, "destination")) { validate.destination = "Missing"; }
  else if (typeof manifest.destination !== "string" || manifest.destination.trim() === "") { validate.destination = "Invalid" }
  //weight
  if (!Object.hasOwn(manifest, "weight")) { validate.weight = "Missing"; }
  else if (typeof manifest.weight !== "number" || manifest.weight <= 0 || Number.isNaN(manifest.weight)) { validate.weight = "Invalid"; }
  //unit
  if (!Object.hasOwn(manifest, "unit")) { validate.unit = "Missing" }
  else if (manifest.unit !== "lb" && manifest.unit !== "kg") { validate.unit = "Invalid"; }
  //hazmat
  if (!Object.hasOwn(manifest, "hazmat")) { validate.hazmat = "Missing"; }
  else if (typeof manifest.hazmat !== "boolean") { validate.hazmat = "Invalid" }
  return validate;
}

function processManifest(manifest) {
  const result = validateManifest(manifest);
  if (Object.keys(result).length === 0) {
    console.log(`Validation success: ${manifest.containerId}`);
    const units = normalizeUnits(manifest).weight;
    console.log(`Total weight: ${units} kg`);
  }
  else console.log(`Validation error: ${manifest.containerId}`);
  console.log(validateManifest(manifest));
};

Your browser information:

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

Challenge Information:

Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Welcome to the forum @karolina42!

Try fixing the syntax of your else statement.

Happy coding!

I see it now, thank you