Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I don’t know what’s going on with my code I can’t seem to get my head around it

Your code so far

function normalizeUnits(manifest){
  const normalizedManifest = {...manifest};

  if(manifest.units === "lb") {
     normalizedManifest.weight = manifest.weight * 0.45;
     normalizedManifest.unit = "kg";
  }
  return normalizedManifest;
}

function validateManifest(manifest){
  const result = {};

  if(manifest.containerId === undefined){
    result.containerId = "Missing";
  } else if(!Number.isInteger(manifest.containerId) || manifest.containerId <= 0){
    result.containerId = "Invalid";
  }

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

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

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


  if (manifest.hamzat === undefined){
    result.hamzat = "Missing";
  } else if (typeof manifest.hamzat !== "boolean"){
    result.hamzat = "Invalid";
  }

  return result;
}


function processManifest(manifest){
  const validationResult = validateManifest(manifest);

  if(Object.keys(validationResult).lenght === 0){
    console.log(`Validation success:${manifest.containerId}`);
   
    const normalizedManifest = normalizeUnits(manifest);

    console.log(`Total weight: ${normalizedManifest.weight} kg`);

  }

  else {
    console.log(`Validation error: ${manifest.containerId}`);

    console.log(validationResult);
  }
}

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 Edg/150.0.0.0

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

Hey @Codex4,

There are a lot of typos in your code. Check to make sure each property you reference from the manifest is spelled correctly. And when you copy the manifest into another variable, use the variable you copied to instead of reverting back to the manifest you copied from. Also, careful with spacing in your messages.

Happy coding