# Build a Cargo Manifest Validator

**URL:** <https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/790294>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [May 30, 2026, 5:46pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/790294 "2026-05-30T17:46:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![besaidaurochs07](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/besaidaurochs07/32/416253_2.png) [@besaidaurochs07](https://forum.freecodecamp.org/u/besaidaurochs07)\
**Post date:** [May 30, 2026, 5:46pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/790294/1 "2026-05-30T17:46:45Z")

</div>

It’s telling me that I should get a specific output (with all keys missing) when I put in an empty object ({}). I’m getting that when I console.log but it’s not letting me pass. Help?

```auto
function normalizeUnits(manifest) {
  let copy = {
    containerId: manifest.containerId,
    destination: manifest.destination,
    weight: manifest.unit === "kg" ? manifest.weight : Number(parseFloat(manifest.weight * 0.45)),
    unit: "kg",
    hazmat: manifest.hazmat
  };
  return copy;
}

function validateManifest(manifest){
  let copy = {};
  console.log(manifest.unit);
  if (manifest.containerId === undefined) {
    copy.containerId = "Missing";
  } else if (typeof(manifest.containerId) !== "number") {
    copy.containerId = "Invalid";
  } 
  if (manifest.destination === undefined) {
    copy.desination = "Missing";
  } else if (typeof(manifest.destination) !== "string") {
    copy.destination = "Invalid";
  } 
  
  if (manifest.weight === undefined) {
    copy.weight = "Missing";
  } else if (typeof(manifest.weight) !== "number") {
    copy.weight = "Invalid";
  } 
  if (manifest.unit === undefined) {
    copy.unit = "Missing";
  } else if (manifest.unit !== "lb" && manifest.unit !== "kg") {
    copy.unit = "Invalid";
  } 
  if (manifest.hazmat === undefined) {
    copy.hazmat = "Missing";
  } else if (typeof(manifest.hazmat) !== "boolean") {
    copy.hazmat = "Invalid";
  } 
  return copy;
}

const object = {
  containerId: 68,
  destination: "Salinas",
  weight: 101,
  unit: "lb",
  hazmat: true
}

const objectTwo = {};

console.log(validateManifest(objectTwo));   

```

---

<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:** [May 30, 2026, 6:10pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/790294/2 "2026-05-30T18:10:28Z")

</div>

Welcome to the forum @besaidaurochs07,

Here’s an excerpt from the instructions:

> - `containerId`: a positive integer identifying the associated cargo container.

> - `weight`: a positive number representing the cargo’s weight.

Is zero a positive number? Can `containerId` be any type of number?

You should have more validation checks for invalid values. Use what the tests expect to help you.

```auto
Edit:
[quote="besaidaurochs07, post:1, topic:790294"]
` copy.desination = "Missing";`
[/quote]

You have a typo.

```

Happy coding

---

<div class="post-metadata">

**Author:** ![besaidaurochs07](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/besaidaurochs07/32/416253_2.png) [@besaidaurochs07](https://forum.freecodecamp.org/u/besaidaurochs07)\
**Post date:** [June 1, 2026, 4:19pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/790294/3 "2026-06-01T16:19:33Z")

</div>

Thanks so much for the help! The typo was what was doing it.  
I’m still having trouble though. It says processManifest isn’t producing the right output even though the console log says it is? Here’s the code.

```auto
function normalizeUnits(manifest) {
  let copy = {
    containerId: manifest.containerId,
    destination: manifest.destination,
    weight: manifest.unit === "kg" ? manifest.weight : Number(parseFloat(manifest.weight * 0.45)),
    unit: "kg",
    hazmat: manifest.hazmat
  };
  return copy;
}

function validateManifest(manifest){
  let copy = {};
  //console.log(manifest.unit);
  if (manifest.containerId === undefined) {
    copy.containerId = "Missing";
  } else if (typeof(manifest.containerId) !== "number" || manifest.containerId <= 0 || manifest.containerId === null || !Number.isInteger(manifest.containerId)) {
    copy.containerId = "Invalid";
  } 
  if (manifest.destination === undefined) {
    copy.destination = "Missing";
  } else if (typeof(manifest.destination) !== "string" || manifest.destination.trim() === "") {
    copy.destination = "Invalid";
  } 
  
  if (manifest.weight === undefined) {
    copy.weight = "Missing";
  } else if (typeof(manifest.weight) !== "number" || manifest.weight <= 0 || Number.isNaN(manifest.weight)) {
    copy.weight = "Invalid";
  } 
  if (manifest.unit === undefined) {
    copy.unit = "Missing";
  } else if (manifest.unit !== "lb" && manifest.unit !== "kg") {
    copy.unit = "Invalid";
  } 
  if (manifest.hazmat === undefined) {
    copy.hazmat = "Missing";
  } else if (typeof(manifest.hazmat) !== "boolean") {
    copy.hazmat = "Invalid";
  } 
  return copy;
}

function processManifest(manifest) {
  let validated = validateManifest(manifest);
  console.log(validated);
  //console.log(Object.keys(validated));
  if (Object.keys(validated).length === 0) {
    console.log(`Validation success: ${manifest.containerId}`);
    let newWeight = normalizeUnits(manifest);
    console.log(`Total weight: ${newWeight.weight} ${newWeight.unit}`);
  } else {
    console.log(`Validation error: ${manifest.containerId}`);
    console.log(validated); 
  }
}; 

const object = {
  containerId: 68,
  destination: "Salinas",
  weight: 101,
  unit: "lb",
  hazmat: true
};

const objectTwo = {};

const objectThree = {
  containerId: 55,
  destination: "Carmel",
  weight: 400,
  unit: "lb",
  hazmat: false
};

processManifest(objectThree);   

```

---

<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:** [June 1, 2026, 5:16pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/790294/4 "2026-06-01T17:16:17Z")

</div>

> [@besaidaurochs07](#):
>
> ` console.log(validated);`

Please remove or comment out this line in your `processManifest` function. It’s confusing the tests.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [June 29, 2026, 5:16pm UTC](https://forum.freecodecamp.org/t/build-a-cargo-manifest-validator/790294/5 "2026-06-29T17:16:57Z")

</div>

Closed on June 29, 2026, 5:16pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
