Stuck on #15 Build a Cargo Manifest Validator

  1. If the input manifest object is not valid, your validateManifest function should return an object describing missing and/or invalid properties. ( My code works as intended, but I couldn’t fulfill this requirement. )
const validateManifest = manifest => {
  const result = {}
  
  const props = ['containerId','destination', 'weight', 'unit', 'hazmat'];
  
  props.forEach((p)=>{
    if(manifest.hasOwnProperty(p)){
      if(p === 'containerId' && (!Number.isInteger(manifest[p]) || manifest[p] <=0)){
        result[p] = 'Invalid'
      }else if (p === 'destination' && (typeof manifest[p] !== 'string' || !manifest[p].trim().length) ){
        result[p] = 'Invalid'
      }else if (p === 'weight' && (manifest[p] <0 || isNaN(manifest[p])) ){
        result[p] = 'Invalid'
      }else if (p === 'unit' && manifest[p] !== 'kg'&& manifest[p] !== 'lb' ){
        result[p] = 'Invalid'
      }else if (p === 'hazmat' && typeof  manifest[p] !== 'boolean'){
        result[p] = 'Invalid'
      }
    }else{
      result[p] = 'Missing';
    }
  })

  return result;
}

  return manifestCopy;
}

Hey @nikitakoyaki,

can you explain what return manifestCopy at the very bottom is supposed to do? Also check your weight validation, the lab specifics that weight must be a positive number.

return manifestCopy this is not actually included. I already passed it! I figured the weight validation should also check if it’s not a number and a zero. Thanks!

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.