Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Hello
I am stuck on step 14. “If the input manifest object is not valid, your validateManifest function should return an object describing missing and/or invalid properties.” It seems to me that It is working also I have all the steps from before completed. Would love some guidance.

Your code so far

function normalizeUnits(manifest) {
  let copy = {... manifest};
  if (copy.unit == "lb") {
    copy.weight = (copy.weight) * 0.45;
    copy.unit = "kg";
  }
  return copy;
}
function validateManifest(manifest) {

  let copy = {containerId: manifest.containerId, destination: manifest.destination, weight: manifest.weight, unit: manifest.unit, hazmat: manifest.hazmat}
  
  if (copy.containerId === undefined) {
    copy.containerId = "Missing";
  } else if (copy.containerId > 0 && copy.containerId % 1 ==0) {
    delete copy.containerId;
  } else
  copy.containerId = "Invalid";
  
  if (copy.destination === undefined) { 
    copy.destination = "Missing";
  } else if (typeof copy.destination == "string") {
    if (copy.destination.trim() == "") {
      copy.destination = "Invalid";
    } else
    delete copy.destination;
  } else
  copy.destination = "Invalid";
  
  if (copy.weight === undefined) {
    copy.weight = "Missing";
  } else if (copy.weight > 0) {
    delete copy.weight;
  } else
  copy.weight = "Invalid";
  
  if (copy.unit === undefined) {
    copy.unit = "Missing";
  } else if (copy.unit == "kg" || copy.unit == "lb") {
    delete copy.unit;
  } else
  copy.unit = "Invalid";
  
  if (copy.hazmat === undefined) {
    copy.hazmat = "Missing";
  } else if (copy.hazmat == true || copy.hazmat == false) {
    delete copy.hazmat;
  } else
  copy.hazmat = "Invalid"
  
  return copy;
}
console.log(validateManifest({ destination: "  " }));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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

Hi @wiktorsmolenski ,

Why are you deleting?

console.log(validateManifest({
containerId: 1,
destination: “Monterey, California, USA”,
weight: 831,
unit: “lb”,
hazmat: false
}));

What does is returned with this function call? Is that what you expect?

Happy coding!

It does return empty object for me and everything is valid so I think result are as I expect. I am deleting because at the beginning I created copy and only errors should be returned. Meanwhile I finished all the other steps and only step 14 has error. :frowning:

How is unit: "lb" valid?

in instructions is is said “kg” or “lb”

True. Don’t know why I thought the units should be normalized at that point.

What about this test?
console.log(validateManifest({ containerId: "10", destination: " ", weight: "1", hazmat: "something" }));

Failing Test #14 points to an issue in your validateManifest function, so please review the related user stories to make sure you have implemented each one of them correctly.

I see what you mean here I fixed it but still have a problem with step 14 I will look through user stories and check if I missed something else.