Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Hi forum,
All of the steps have passed except for step 21. My current code is the following:

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.toLowerCase() === "lb") {
    newManifest.weight = Number((newManifest.weight * 0.45));
    newManifest.unit = "kg";
  }

  return newManifest;
};

function validateManifest(manifest) {
  let copy = {}

  if (manifest.containerId === undefined) {
    copy.containerId = 'Missing';
  } else if (manifest.containerId < 1 || typeof manifest.containerId !== 'number' || manifest.containerId % 1 !== 0) {
    copy.containerId = 'Invalid';
  }

  if (manifest.destination === undefined) {
    copy.destination = 'Missing';
  } else if (  typeof manifest.destination !== 'string'  || manifest.destination.trim() === "") {
    copy.destination = 'Invalid';
  }

  if (manifest.weight === undefined) {
    copy.weight = 'Missing';
  } else if (manifest.weight < 1 || typeof manifest.weight !== 'number' || Number.isNaN(manifest.weight)) {
    copy.weight = 'Invalid';
  }

  if (manifest.unit === undefined) {
    copy.unit = 'Missing';
  } else if (manifest.unit !== 'kg' && manifest.unit !== 'lb') {
    copy.unit = 'Invalid';
  }

  if (manifest.hazmat === undefined) {
    copy.hazmat = 'Missing';
  } else if (typeof manifest.hazmat !== 'boolean') {
    copy.hazmat = 'Invalid';
  }

  return copy
}


function processManifest(manifest){
    let newManifest = validateManifest(manifest);
    if(newManifest.containerId === "Invalid" || newManifest.containerId === "Missing"){
        console.log(`Validation error: ${manifest.containerId}`);
        console.log(newManifest);
    } else {
        let normalizedManifest = normalizeUnits(manifest);
        console.log(`Validation success: ${manifest.containerId}`);
        console.log(`Total weight: ${normalizedManifest.weight} kg`);
    }
}


processManifest(cargoManifest); 




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 YaBrowser/26.6.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 @makarovanton301,

Try declaring normalizeUnits with let instead of const since the tests are reassigning the functions.

Happy coding