Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Hey Guys,
I have a problem with test 15. Can someone help me!!

Your code so far

const cargo = {
  containerId: 19,
  destination: "Juba South Sudan",
  weight: 831,
  unit: "lb",
  hazmat: false
}
const carGo ={ 
  containerId: -88, 
  destination: "Soledad", 
  weight: NaN, 
  unit: "pound", 
  hazmat: "1" }
function normalizeUnits(manifest){
  const {...newManifest} = manifest;
  if(newManifest.unit ==="lb"){
    newManifest.weight = newManifest.weight * 0.45;
    newManifest.unit = "kg";
  }
  return newManifest;
}

function validateManifest(manifest){
  const validate = {};
  if(manifest.containerId === undefined){
    validate.containerId = "Missing";
  }else if(Number.isInteger(manifest.containerId) !== true || manifest.containerId <= 0){
    validate.containerId = "Invalid";
  }

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

  if(manifest.weight === undefined){
    validate.weight = "Missing";
  }else if(typeof manifest.weight !== "number" || manifest.weight <= 0 ||Number.isNaN(manifest.weight) !== false ){
    validate.weight = "Invalid";
  }

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

  if(!("hazmat" in manifest)){
    validate.hazmat = "Missing";
  }else if(typeof manifest.hazmat !== "boolean"){
    validate.hazmat = "Invalid";
  };
  
  return validate;
}



function processManifest(manifest){
  const process = validateManifest(manifest);
  
  if(Object.keys(process).length === 0){
    const accessWeight = normalizeUnits(manifest);
    console.log(`Validation success: ${manifest.containerId}`);
    console.log(`Total weight: ${accessWeight.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/147.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 @ajakmathiang19!

What do you see in the console when you test your code like this?

console.log(validateManifest({ 
  containerId:  55, 
  destination: "  Soledad   ", 
  weight: 10, 
  unit: "lb", 
  hazmat: false }))

Is that what you expect to see?

Happy coding!