Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

All my tests are passing except for test 15. My code returns an object with a description of Invalid or missing items so I’m not sure where I am going wrong. Hint would be greatly appreciated.

Your code so far

function normalizeUnits(manifest) {
  const copy = { ...manifest };

  if (copy.unit === "lb") {
    copy.unit = "kg";
    copy.weight = copy.weight * 0.45;
  }

  return copy;
}

function validateManifest(manifest) {
  const result = {};

  if (!("containerId" in manifest)) {
    result.containerId = "Missing";
  }
  else if ((typeof manifest.containerId !== "number") || (manifest.containerId <= 0) || (!Number.isInteger(manifest.containerId)) || Number.isNaN(manifest.containerId)) {
        result.containerId = "Invalid"
  }

  if (!("destination" in manifest)) {
    result.destination = "Missing";
  }
  else if ((typeof manifest.destination !== "string") || (manifest.destination.trim() === "")) {
    result.destination = "Invalid";
  }

  if (!("weight" in manifest)) {
    result.weight = "Missing";
  }
  else if ((typeof manifest.weight !== "number") || (manifest.weight < 0) || Number.isNaN(manifest.weight)) {
    result.weight = "Invalid";
  }

  if (!("unit" in manifest)) {
    result.unit = "Missing";
  }
  else if (manifest.unit !== "kg" && manifest.unit !== "lb") {
    result.unit = "Invalid"
  }
  if (!("hazmat" in manifest)) {
    result.hazmat = "Missing";
  }
  else if (typeof manifest.hazmat !== "boolean") {
    result.hazmat = "Invalid"
  }

  return result;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.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 to the forum @rayalva407!

From the instructions:

  • weight: a positive number representing the cargo’s weight.

Is zero a positive number?

Happy coding

Wow taking breaks is essential because I could have sworn I checked this 2 or 3 times. Lesson learned! Thank you sooo much!