Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I’m not sure why my code is passing. for my process manifest function. i have made changes to my validate function from the last post i made to make sure it passes all the test while individually changing what is being tested. Now with this new function i have made the if statement check for the array of key from the obj to see if its empty. it comes out true and false according to the different obj i pass through this lab. i can’t seem to pass 22, 23, 24, and 26.

Your code so far

const cargoManifest = { containerId: -88, destination: "Soledad", weight: NaN };


function normalizeUnits(manifest) {
  const copyManifest = {...manifest}
  
  if(copyManifest.unit === "lb") {
    copyManifest.weight = convertPoundsToKilo(copyManifest);
    copyManifest.unit = "kg";
  }
  return copyManifest;
};

function convertPoundsToKilo(obj) {
  let convert = obj.weight * 0.45;
  return convert;
};

function validateManifest(manifest) {
  const newManifest = new Object;


  if(!manifest.hasOwnProperty("containerId")) {
    newManifest.containerId = "Missing";
  } else if(!Number.isInteger(manifest.containerId) || manifest.containerId === null || manifest.containerId < 1) {
    newManifest.containerId = "Invalid";
  } else {
    delete newManifest.containerId
  };

  if(!manifest.hasOwnProperty("destination")) {
    newManifest.destination = "Missing";
  } else if(typeof manifest.destination !== "string") {
    newManifest.destination = "Invalid";
  } else if (manifest.destination.trim().length === 0){
    newManifest.destination = "Invalid";
  } else {
    delete newManifest.destination;
  };

  if(!manifest.hasOwnProperty("weight")) {
    newManifest.weight = "Missing";
  } else if(Number.isNaN(manifest.weight) || manifest.weight <= 0) {
    newManifest.weight = "Invalid";
  } else {
    delete newManifest.weight;
  };

  if(!manifest.hasOwnProperty("unit")) {
    newManifest.unit = "Missing";
  } else if(manifest.unit !== "lb" && manifest.unit !== "kg") {
    newManifest.unit = "Invalid";
  } else {
    delete newManifest.unit;
  };

  if(!manifest.hasOwnProperty("hazmat")) {
    newManifest.hazmat = "Missing";
  } else if(manifest.hazmat !== true && manifest.hazmat !== false) {
    newManifest.hazmat = "Invalid";
  } else {
    delete newManifest.hazmat;
  };

  return newManifest; 
}

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

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


// console.log(normalizeUnits(cargoManifest));
// console.log(validateManifest(cargoManifest));
processManifest(cargoManifest);

Your browser information:

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

hello!

kindly recheck User Story #3’s 2nd point for the expected error message.

Thank you! I can’t believe i missed that :laughing: