Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Im stuck on step number 8 an d cant seem to figure out why

Your code so far

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

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

  return manifestCopy
}

function validateManifest(manifest) {
  const errors = {};
  const required = ["containerId", "destination", "weight", "unit", "hazmat"];

  required.forEach(prop => {
    if (!(prop in manifest)) {
      errors.prop = "Missing";
    }
  });

  if (manifest.weight !== undefined && (typeof manifest.weight !== "number" || manifest.weight < 0)) {
    errors.weight = "Invalid";
  }

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

  return errors;
}

function processManifest(manifest) {
  const errors = validateManifest(manifest);
  const isValid = Object.keys(errors).length === 0;

  if (isValid) {
    const normalized = normalizeUnits(manifest);
    console.log(`Validation success: ${manifest.containerId}`);
    console.log(`Total weight: ${normalized.weight} kg`);
  } else {
    console.log(`Validation error: ${manifest.containerId}`);
    console.log(errors);
  }
}

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

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, @dreedtechguy!

Is there a property named prop? How do we need to access a property if it’s a variable?

What if hazmat is missing? Should this code run?

Happy coding!