Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I can’t seem to pass test #15 though i am returning an object

Your code so far



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

  if (manifest.containerId === undefined){
    //console.log(manifest.containerId)
    valideObj.containerId = "Missing";
  } else if (typeof(manifest.containerId) !== "number" || manifest.containerId <= 0 ||  !Number.isInteger(manifest.containerId) || Number.isNaN(manifest.containerId)){
    valideObj.containerId = "Invalid";
  } 
  
  //console.log(manifest.destination.trim() === "")
  if (manifest.destination === undefined){
    valideObj.destination = "Missing";
  } else if ( typeof(manifest.destination) !== "string"|| manifest.destination.trim() === ""){
    valideObj.destination = "Invalid";
  } 


 //console.log(typeof(manifest.destination))
  if (manifest.weight === undefined){
    valideObj.weight = "Missing";
  } else if ( typeof(manifest.weight) !== "number" || manifest.weight <= 0 ||  Number.isNaN(manifest.weight) ){
    valideObj.weight = "Invalid";
  } 

  if (manifest.unit === undefined){
    valideObj.unit = "Missing";
  } else if (typeof(manifest.unit) !== "string" || manifest.unit.length > 2 || manifest.unit.trim() === ""){
    valideObj.unit = "Invalid";
  } 

 
 // console.log(typeof(""))
  if (manifest.hazmat === undefined){
    valideObj.hazmat = "Missing";
  } else if (typeof(manifest.hazmat) !== "boolean"){
    valideObj.hazmat = "Invalid";
  } 
  //console.log(manifest)
  return valideObj;
}

const processManifest = manifest => {
  
  const validatedManifest = validateManifest(manifest);
  if (Object.keys(validatedManifest).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(validatedManifest);
  }
}

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:149.0) Gecko/20100101 Firefox/149.0

Challenge Information:

Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Welcome to the forum @dontaa372!

Please post your normalizeManifest function. For some reason, it wasn’t included.

Happy coding!

Here is the normalization function :

const normalizeUnits = manifest => {

const newObj = {};

newObj.containerId = manifest.containerId;

newObj.destination = manifest.destination;

newObj.weight = manifest.unit === “kg”? manifest.weight: (manifest.weight * 0.45);

newObj.unit = “kg”;

newObj.hazmat = manifest.hazmat;

return newObj;

}

and the code is only unable to pass the test #15 and i don’t know why

hello!

unit: “ab” should be "Invalid”. Your code does not mark it as invalid.

yeah, that was i didn’t check for both kg and lb at the same time, thanks!

1 Like