Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Getting error on 2.6, and 18. It says i dont have function named normalizeUnits, validateManifest and processManifest with param manifest.

Your code so far

function normalizeUnits(manifest ) {
  var newObj = {...manifest};
  if(newObj.unit !== undefined && newObj.unit == "lb" && newObj.weight !== undefined) {
    newObj.weight = manifest.weight * 0.45;
    newObj.unit = "kg";
  }
  return newObj;
}

function validateManifest(manifest) {
  var newObj = {};

  if (!Object.hasOwn(manifest, 'containerId') || manifest.containerId == 'Missing') {
    newObj.containerId = 'Missing';
  }
  if (!Object.hasOwn(manifest, 'destination') || manifest.destination == 'Missing') {
    newObj.destination = 'Missing';
  }
  if (!Object.hasOwn(manifest, 'weight') || manifest.weight == 'Missing') {
    newObj.weight = 'Missing';
  }
  if (!Object.hasOwn(manifest, 'unit') || manifest.unit == 'Missing') {
    newObj.unit = 'Missing';
  }   
  if (!Object.hasOwn(manifest, 'hazmat') || manifest.hazmat == 'Missing') {
    newObj.hazmat = 'Missing';
  }

  if ((!manifest.containerId || manifest.containerId <= 0 || !Number.isInteger(manifest.containerId)) && !Object.hasOwn(newObj, "containerId")) {
    newObj.containerId = 'Invalid';
  }

  if ((!manifest.weight || manifest.weight <= 0) && !Object.hasOwn(newObj, 'weight')) {
    newObj.weight = 'Invalid';
  }

  var allowedUnit = ['kg', 'lb'];

  if ((!manifest.unit || !allowedUnit.includes(manifest.unit)) && !Object.hasOwn(newObj, 'unit')) {
    newObj.unit = 'Invalid';
  }

  if ((typeof manifest.hazmat !== 'boolean') && !Object.hasOwn(newObj, 'hazmat')) {
    newObj.hazmat = 'Invalid';
  }

  if ((typeof manifest.destination !== 'string' || manifest.destination?.trim() === "") && !Object.hasOwn(newObj, 'destination')) {
    newObj.destination = 'Invalid';
  }

  return newObj;
}

function processManifest(manifest) {
  var validate = validateManifest(manifest);
  if (Object.keys(validate).length === 0) {
    console.log(`Validation success: ${manifest.containerId}`);
    var weight = normalizeUnits(manifest).weight;
    console.log(`Total weight: ${weight} 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/151.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 @Shadow42

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

Happy coding