Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I can’t pass the test 18, 19, and 21. The output for my code in the processManifest() function appears to be the same as the user story. But it’s not accepting it. May I kindly get enlightened as to what I’m overlooking here? TIA!

Your code so far

// Test Data
const manifest = {
  containerId: 3,
  destination: "Streets",
  weight: 831,
  unit: "pounds",
  hazmat: false
}


function normalizeUnits(manifest) {

  const manifestCopy = {...manifest};
  const lbToKg = manifestCopy.weight * 0.45;
  const unitToKg = "kg";

  if (manifestCopy.unit === "lb") {
    manifestCopy.weight = lbToKg;
    manifestCopy.unit = unitToKg;
  }

  return manifestCopy;

}

function validateManifest(manifest) {

  const manifestCopy = {...manifest}
  let invalidManifestCopy = {};

  // Container ID
  if (manifestCopy.containerId === undefined) {
    invalidManifestCopy.containerId = "Missing";
  } else if (typeof manifestCopy.containerId !== "number" || manifestCopy.containerId <= 0 || !Number.isInteger(manifestCopy.containerId)) {
    invalidManifestCopy.containerId = "Invalid";
  }

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

  // Weight
  if (manifestCopy.weight === undefined) {
    invalidManifestCopy.weight = "Missing";
  } else if (typeof manifestCopy.weight !== "number" || !Number.isInteger(manifestCopy.weight) || manifestCopy.weight <= 0) {
    invalidManifestCopy.weight = "Invalid";
  }

  // Unit
  if (manifestCopy.unit === undefined) {
    invalidManifestCopy.unit = "Missing";
  } else if (manifestCopy.unit !== "lb" && manifestCopy.unit !== "kg") {
    invalidManifestCopy.unit = "Invalid";
  }

  // Hazardous material
  if (manifestCopy.hazmat === undefined) {
    invalidManifestCopy.hazmat = "Missing";
  } else if (typeof manifestCopy.hazmat !== "boolean") {
    invalidManifestCopy.hazmat = "Invalid";
  }


  return invalidManifestCopy;

}
// console.log(validateManifest(manifest));

function processManifest(manifest) {
  const valid = validateManifest(manifest);
  const normalizeWeight = normalizeUnits(manifest);

  if (Object.keys(valid).length === 0) {
    console.log(`Validation Success: ${manifest.containerId}`);
    console.log(`Total weight: ${normalizeWeight.weight} ${normalizeWeight.unit}`); 
  } else {
    console.log(`Validation error: ${manifest.containerId}`);
    console.log(validateManifest(manifest));
  }
}

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36

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 @develobray,

Are you sure your message matches exactly to the message in the instructions?

Happy coding

Got it! Thank you so much!