Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I can’t pass test 21, 25, 26 even though it pass the test for calling the function processManifest() with an object

Your code so far

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


const validateManifest = (manifest) => {
  const errors = {}

  if(manifest.containerId === undefined || manifest.containerId == 'Missing') {errors.containerId = 'Missing'}
  else if(!Number.isInteger(manifest.containerId) || manifest.containerId <= 0) {errors.containerId = 'Invalid'}

  if(manifest.destination === undefined || manifest.destination == 'Missing') errors.destination = 'Missing'
  else if(String(manifest.destination).trim() == '' || typeof manifest.destination !== 'string') errors.destination = 'Invalid'

  if(manifest.weight === undefined || manifest.weight == 'Missing') errors.weight = 'Missing';
  else if(isNaN(manifest.weight) || manifest.weight < 1) errors.weight = 'Invalid'

  if(manifest.unit === undefined || manifest.unit == 'Missing') errors.unit = 'Missing'
  else if(!(manifest.unit == "kg" || manifest.unit == "lb"))errors.unit = 'Invalid'

  if(manifest.hazmat === undefined || manifest.hazmat == 'Missing')errors.hazmat = 'Missing'
  else if(!(manifest.hazmat === true || manifest.hazmat === false))errors.hazmat = 'Invalid'
  return errors
}

function processManifest(manifest){
  const validated = validateManifest(manifest);
  const {containerId, weight} = normalizeUnits(manifest);

  if(Object.keys(validated).length === 0){
    console.log(`Validation success: ${containerId}`)
    console.log(`Total weight: ${weight} kg`)
  } else {
    console.log(`Validation error: ${containerId}`)
    console.log(validated)
  }
}

processManifest({ containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false })

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.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

I solved it, I’m using an arrow function for normalizeUnits and validateManifest which I shouldn’t have.

you can use arrow functions, the issue is that using const is having the test fails as they reassign the functions for some tests