# Build a cargo manifest validator

**URL:** <https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/802458>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [October 19, 2026, 3:53pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/802458 "2026-10-19T15:53:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MmathapeloNare](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@MmathapeloNare](https://forum.freecodecamp.org/u/MmathapeloNare)\
**Post date:** [October 19, 2026, 3:53pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/802458/1 "2026-10-19T15:53:48Z")

</div>

## Tell us what’s happening:

Tests 2, 6 and 18 fail, while the other 24 tests pass, including all the behavior tests for these same functions:

- 2. You should have a function named `normalizeUnits` with a `manifest` parameter.

- 6. You should have a function named `validateManifest` with a `manifest` parameter.

- 18. You should have a function named `processManifest` with a `manifest` parameter.

The hint I get is: “Your code does not contain a declared function named `normalizeUnits` that takes a `manifest` parameter. Define a function using the syntax `function normalizeUnits(manifest) { … }` and try again.” My functions are declared in exactly that form, so I can’t see what’s wrong.

I’ve tried - Plain `function name(manifest) { … }` declarations (not `const`, so test 1 passes)

- `let` arrow functions, after a suggestion on the forum

- Replacing object spread (`{ …manifest }`) with `Object.assign({}, manifest)`

- Removing `Object.hasOwn` and checking for `=== undefined` instead

- Resetting the lab and pasting the code in fresh

## Your code so far

```auto
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);

```

## 

Lesson URL (copy - paste from your browser’s address bar)

---

<div class="post-metadata">

**Author:** ![dhess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dhess/32/406235_2.png) [@dhess](https://forum.freecodecamp.org/u/dhess)\
**Post date:** [October 19, 2026, 4:12pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/802458/2 "2026-10-19T16:12:43Z")

</div>

Hi @MmathapeloNare,

When I run your code, Test #1 fails with:

> You should not declare `normalizeUnits`, `validateManifest`, or `processManifest` using `const`, since the tests need to reassign them.

And when I make the changes to pass Test #1, your code passes.

Happy coding

---

<div class="post-metadata">

**Author:** ![MmathapeloNare](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@MmathapeloNare](https://forum.freecodecamp.org/u/MmathapeloNare)\
**Post date:** [October 20, 2026, 9:15am UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/802458/3 "2026-10-20T09:15:22Z")

</div>

Thank you so much, I fixed what needed to be fixed and the tests passed.
