Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

My code does not pass requirements 21, 25, and 26 despite returning all the right results.

Your code so far

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

const validateManifest = (manifest) => {

  let errors = {};
  
  if(Object.hasOwn(manifest, "containerId")){
    if(manifest.containerId === null || manifest.containerId <= 0 || 
      typeof manifest.containerId !== "number" || manifest.containerId % 1 !== 0 || manifest.containerId.toString()?.includes('.'))
    {
      errors.containerId = "Invalid";
    }
  } else {
    errors.containerId = "Missing";
  }

  if(Object.hasOwn(manifest, "destination")){
    if (typeof manifest.destination !== "string" || manifest.destination === null || manifest.destination.trim() === "")
    {
      errors.destination = "Invalid";
    }
  } else {
      errors.destination = "Missing";
  }

  if (Object.hasOwn(manifest, "weight")){
    if(Number.isNaN(manifest.weight)|| 
        manifest.weight === null || manifest.weight <= 0)
    {
      errors.weight = "Invalid";
    }
  } else {
    errors.weight = "Missing";
  }

  if(Object.hasOwn(manifest, "unit")){
    if (manifest.unit === null || typeof manifest.unit !== "string" || manifest.unit !== "lb" && manifest.unit !== "kg")
    {
      errors.unit = "Invalid";
    }
  } else {
    errors.unit = "Missing";
  }

  if(Object.hasOwn(manifest, "hazmat")){
    if (manifest.hazmat === null || typeof manifest.hazmat !== "boolean")
    {
      errors.hazmat = "Invalid";
    }
  } else {
    errors.hazmat = "Missing";
  } 
  return errors;
}
  
const processManifest = (manifest) => {

if(manifest === null || manifest === undefined) manifest = {};
const errors = validateManifest(manifest);

  if (Object.keys(errors).length === 0){
    const normalizedManifest = normalizeUnits(manifest);
    console.log(`Validation success: ${manifest.containerId}`);
    console.log(`Total weight: ${normalizedManifest.weight} kg`);
    
  } else {
    console.log(`Validation error: ${manifest.containerId}`);
    console.log(validateManifest(manifest));
    
  }
} 



Lesson URL: https://www.freecodecamp.org/learn/javascript-v9/lab-cargo-manifest-validator/lab-cargo-manifest-validator?messages=success[0]%3Dflash.signin-success

Welcome to the forum @Fertini,

Please declare your arrow functions with let rather than const since the tests are reassigning those functions.

Staff is working on getting a note up about that.

Happy coding

Thank you! Happy I brought it up!

omg I was tearing my hair out because I had const instead of let for these declarations even though the application worked exactly as the story requested