Build a Cargo Manifest Validator - Build a Cargo Manifest Validator Steps 21, 25, 26

Tell us what’s happening:

Steps 21, 25, 26 will not validate, cannot determine where the code is not logging correctly. I have modified my code multiple times while checking the validation in case it was a small error somewhere, though it seems to point to the processManifest function. I even went as far as to compare my solution to the GitHub solution, and update my functions to resemble it to make sure I didn’t miss anything. I am stumped at this point. I assume that I am missing something simple, but can’t see it. Any help would be appreciated!

Your code so far

const weightConversionRate = 0.45

const normalizeUnits = function(manifest) {
  const newManifest = {...manifest};
  if (newManifest.unit === "lb") {
    newManifest.unit = "kg";
    newManifest.weight *= weightConversionRate;
  }
  return newManifest;
}

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

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

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

  if (manifest.unit === undefined) {
    testingManifest.unit = "Missing";
  }
  else if (manifest.unit !== "lb" && manifest.unit !== "kg") {
      testingManifest.unit = "Invalid";
  } 

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

  return testingManifest;
}

const processManifest = function(manifest) {
  const validatedManifest = validateManifest(manifest);
  
  if (Object.keys(validatedManifest).length > 0) {
    console.log(`Validation error: ${manifest.containerId}`);
    console.log(validatedManifest);
  } 
  else {
    const normalizedManifest = normalizeUnits(manifest);
    console.log(`Validation success: ${manifest.containerId}`);
    console.log(`Total weight: ${normalizedManifest.weight} kg`);
  }
}

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

This is not the correct syntax to create a regular function or an arrow function.

Please review this theory lecture for examples:
Working with Functions - What Are Arrow Functions, and How Do They Work? | Learn | freeCodeCamp.org

I suggest going with regular functions to pass the tests since something in the tests seems to have changed and arrow functions are no longer passing.

Happy coding

Thank you for the response. Your noted change does complete the lab, but I am still lost as to why this was an issue.

What I used is the correct syntax to create an anonymous function, and nowhere in the instructions or tests does it clarify this information. The user stories do specify to use a named function, but then tests 1, 5, and 17 all should’ve failed for not having a function named correctly.

In reference to the lesson you sent, in the previous lesson we learned how to create anonymous functions and assign them to variables,

which is exactly what I did when arrow functions didn’t work. I see now I should’ve looked into it further, since both options use anonymous functions. I guess that means the tests themselves aren’t checking correctly for those? Or are arrow functions supposed to work for this lab?

When I did this lab, I used arrow functions and they passed the tests. That’s why I mentioned that the tests must have changed.