Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

getting confused why its showing issue in step 15 first it was showing for step 7

Your code so far

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

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

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

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

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

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

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Welcome to the forum @pawansh803!

Does it make sense to manipulate the value of unit when you are testing for validity?

Happy coding!

i dont get isn’t that the point to check if they are lb or kg

Welcome back, @kimkiara520!

Please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Help button image located on each challenge. This will automatically import your code in a readable format and pull in the challenge URL while still allowing you to ask any question about the challenge or your code.

Thank you.

Happy coding!

thanks for your guidance sir.