Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I am working on the Cargo Manifest Validator lab and although the functional requirements pass, the process ones will not and I have no idea why. I keep getting this message:
If the input manifest object is valid, your processManifest function should log a success message with the object’s containerId, and then log the object’s weight in kilograms. You should use normalizeUnits() for the conversion and have two console.log() calls.

Your code so far

const normalizeUnits = (manifest) => {
  const newManifest = {...manifest};

  if(newManifest.unit === "lb") {
    newManifest.unit = "kg";
    newManifest.weight *= 0.45;
    return newManifest;
  }

  return newManifest;
}

const validateManifest = (manifest) => {

  const containerId = manifest.containerId;
  const destination = manifest.destination;
  const weight = manifest.weight;
  const unit = manifest.unit;
  const hazmat = manifest.hazmat;

  const validatedManifest = {};

  if(containerId === undefined) {
    validatedManifest.containerId = "Missing";
  } else if (containerId <= 0 || typeof(containerId) != 'number' || 
          !Number.isInteger(containerId) || Number.isNaN(containerId)) {
    validatedManifest.containerId = "Invalid";
  } 

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

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

  if((typeof(unit) === 'string' && unit.trim() === "") ||
     unit === undefined) {
    validatedManifest.unit = "Missing";
  } else if (unit !== "lb" && unit !== "kg" ) {
    validatedManifest.unit = "Invalid";
  }

  if(hazmat === undefined) {
    validatedManifest.hazmat = "Missing";
  } else if (hazmat !== true && hazmat !== false ) {
    validatedManifest.hazmat = "Invalid";
  }

  return validatedManifest;
}

const processManifest = (manifest) => {

  //const manifestValid = validateManifest(manifest);

  if(Object.keys(validateManifest(manifest)).length === 0) {
    console.log(`Validation success: ${manifest.containerId}`);
    const normalized = normalizeUnits(manifest);
    //const weight = normalizeUnits(manifest).weight;
    console.log(`Total weight: ${normalized.weight} ${normalized.unit}`);
  } else {
    console.log(`Validation error: ${manifest.containerId}`);
    console.log(validateManifest(manifest));
  }
}
const myManifest = { containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false };

processManifest(myManifest);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.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 @crystal.kirscht,

Try declaring your arrow functions with let instead of const since the tests are reassigning those.

Happy coding

That fixed it. Thanks!!

Is there a way to know if a function should be a const or a let? (also there needs to be better hints to let you know what you did wrong - everything in the test/hint were all things I had done)

Yes; I agree and I’m sorry that was not communicated up front. The staff is working on adding a note in the instructions to let you know that arrow functions need to be declared with let because of the tests. I don’t like it because it doesn’t make sense in practice to declare an arrow function definition with let; it’s counterintuitive. On the other hand, defining regular functions instead causes no issues for these tests. So, there’s that.