Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I AM STUCK AT TEST NUMBER: 15,21,25,26 , i completed those task according to the instruction but it still is not showing error

Your code so far

const normalizeUnits= (manifest)=>{
  let copy={
    containerId:manifest.containerId,
    destination:manifest.destination,
    weight:(manifest.unit==="lb")?(manifest.weight * 0.45):manifest.weight ,
    unit:"kg",
    hazmat:manifest.hazmat
  }
  return copy;
}

console.log(normalizeUnits(
   { containerId: 68, destination: "Salinas", weight: 101, unit: "lb", hazmat: true }
));

const validateManifest=(manifest)=>{

  let newObj={};
  if(manifest.containerId===undefined){
    newObj.containerId="Missing";
 
  }
  else if(typeof manifest.containerId !="number"){
    newObj.containerId="Invalid";
 
  }
  else if(manifest.containerId<1 || !Number.isInteger(manifest.containerId)){
    newObj.containerId="Invalid";
 
  }

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

  }
  else if((manifest.destination).trim()===""){
    newObj.destination="Invalid";

  }
  

  if(manifest.weight===undefined){
    newObj.weight="Missing";

  }
  else if(manifest.weight < 0|| Number.isNaN(manifest.weight)){
   newObj.weight="Invalid";

  }

  if(manifest.unit===undefined){
    newObj.unit="Missing";

  }
  else if(typeof manifest.unit!=="string"){
    newObj.unit="Invalid";
  }
  else if(manifest.unit!=="kg"&&manifest.unit!=="lb"){
     newObj.unit="Invalid";

  }
  

  if(manifest.hazmat===undefined){
  newObj.hazmat="Missing";
  }
  else if(typeof manifest.hazmat !="boolean"){
    newObj.hazmat="Invalid";
  }
 
 return (Object.keys(newObj).length===0)? new Object(): newObj; 
  
};

console.log(validateManifest({ containerId: 1, destination: "Santa Cruz", weight: 304, unit: "kg", hazmat: false }));

console.log(validateManifest({}));

console.log(validateManifest({containerId: null, destination: "Santa Cruz", weight: 304, unit: "kg", hazmat: false }));

console.log("\n hey there",validateManifest({containerId: 0, destination: 405, weight: -84, unit: "pounds", hazmat: "no"}));

console.log(validateManifest({containerId: 3.50}));
console.log(validateManifest({destination: "  "}));
console.log(validateManifest({weight: NaN}));



const processManifest= (manifest)=>{
 
   let validate= validateManifest(manifest);
   let normalizedUnits= normalizeUnits(manifest);

   if(Object.keys(validate).length === 0){
   
   console.log(`Validation success: ${manifest.containerId}`);
   console.log(`Total weight: ${normalizedUnits.weight} kg`);
   }

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

};

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

console.log(processManifest({ containerId: -88, destination: "Soledad", weight: NaN }));



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

consider weight: 0, is this valid or not?

what about unit: "KG", is this valid?

for weight i get it but for unit the question specified :unit: a string describing the units for the cargo’s weight property (either "kg" for kilograms or "lb" for pounds).

remember that a lowercase letter and an uppercase letter are not the same character in strings

ok dude thanks for your suggestion about weight :0 , and another problem was I was using arrow function instead of normal one