Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

i cant pass test 14.
its my error.
// running tests
15. If the input manifest object is not valid, your validateManifest function should return an object describing missing and/or invalid properties.
// tests completed
The output shows what is requested, but I still can’t pass the test.
I would be grateful if you could help me find my problem.

Your code so far


let cargo1 = {
 containerId: 0,
  destination: 55,
  weight: 0,
  unit: "lb ",
  hazmat: "sc",
}

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

const validateManifest=(manifest)=>{
  const newObj={}
   if (manifest.containerId === undefined) {
    newObj.containerId = "Missing";
    } else if (
      typeof manifest.containerId !== "number" ||
      !Number.isInteger(manifest.containerId) ||
      manifest.containerId <= 0
      ) {
      newObj.containerId = "Invalid";
      }

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

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

            if (manifest.unit === undefined) {
              newObj.unit = "Missing";
              } else if (
              typeof manifest.unit !== "string" ||
              !["kg", "lb"].includes(manifest.unit.toLowerCase())
               ) {
              newObj.unit = "Invalid";
             }

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

  return newObj;
};

const processManifest = (manifest)=>{
  if(manifest === null || manifest === undefined)        manifest = {};

  const isValidate = validateManifest(manifest);

  if (Object.values(isValidate).length === 0){
    const normalizedWeight = normalizeUnits(manifest);

    console.log(`Validation success: ${manifest.containerId}`)
    console.log(`Total weight: ${normalizedWeight.weight} kg`)
  } else {
    console.log(`Validation error: ${manifest.containerId}`)
    console.log(isValidate)
  }
}

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

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

//test8
// console.log(validateManifest({}));

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

//test10
// console.log(validateManifest({ containerId: 0, destination: 405, weight: -84, unit: "pounds", hazmat: "no" }));

//test11 
// console.log(validateManifest({ containerId: -2 }));

//test12
// console.log(validateManifest({ containerId: 3.50 }));

//test13
// console.log(validateManifest({ destination: "  " }));

//test14
console.log(validateManifest({ weight: NaN }));

//test18
//  processManifest({ containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false })

 //test22
//  processManifest({ containerId: -88, destination: "Soledad", weight: NaN })

 //test23
//  processManifest({ destination: "Watsonville", hazmat: true })




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.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

Welcome to the forum @faezehhzz,

What if the weight is 0.85?

Should you be manipulating a property value before validating it?

Happy coding

if (manifest.weight === undefined) {

        newObj.weight = "Missing";

      } else if (

       typeof manifest.weight !== "number" || manifest.weight < 0 ||

      Number.isNaN(manifest.weight)) {

       newObj.weight = "Invalid"

        };

and

if (manifest.unit === undefined) {

          newObj.unit = "Missing";

          } else if (

          typeof manifest.unit !== "string" ||

          !\["kg","lb"\].includes(manifest.unit)){

          newObj.unit = "Invalid";

         }

editing it like this

still have the error.

Is zero a positive number?

finally found it thank YOU :heart_eyes: