Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

Hi everyone I am currently having an issue where I have the correct things being outputted when it comes to the validateManifest function but it states that I am not actually returning an object where it shows all missing or invalid properties. I am quite stuck here and any help is appreciated! :slight_smile:

  1. If the input manifest object is not valid, your validateManifest function should return an object describing missing and/or invalid properties.

Your code so far

function normalizeUnits (manifest){
  let newManifest = {
    containerId: manifest.containerId, 
    destination: manifest.destination,
    weight: manifest.weight, 
    unit: manifest.unit, 
    hazmat: manifest.hazmat 
  }

  if(newManifest.unit === 'kg')
    return newManifest;

  newManifest.unit = "kg";
  newManifest.weight = newManifest.weight * .45;
  return newManifest;
}

function validateManifest(manifest){
  let newManifest = {};

  if(manifest.hasOwnProperty("containerId")){
    if(manifest.containerId <= 0 || !Number.isInteger(manifest.containerId)){
      newManifest.containerId = "Invalid";
    }
  }else{
    newManifest.containerId = "Missing";
  }

  if(manifest.hasOwnProperty("destination")){
    if(typeof manifest.destination !== 'string' || 
       manifest.destination.trim() === ""){
      newManifest.destination = "Invalid";
    }
  }else{
    newManifest.destination = "Missing";
  }

  if(manifest.hasOwnProperty("weight")){
    if(manifest.weight < 0 || isNaN(manifest.weight)){
      newManifest.weight = "Invalid";
    }
  }else{
    newManifest.weight = "Missing";
  }

  if(manifest.hasOwnProperty("unit")){
    if(manifest.unit !== 'lb' && manifest.unit !== 'kg'){
      newManifest.unit = "Invalid";
    }
  }else{
    newManifest.unit = "Missing";
  }

  if(manifest.hasOwnProperty("hazmat")){
    if(typeof manifest.hazmat !== 'boolean'){
      newManifest.hazmat = "Invalid";
    }
  }else{
    newManifest.hazmat = "Missing";
  }

  return newManifest;
} 

function processManifest(manifest){
  let validated = validateManifest(manifest);
  let message = ``;

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

  return message;
}

console.log(processManifest({ containerId: -88, destination: "Soledad", weight: NaN })) 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0

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

test with this manifest object

  {
    containerId: -6,
    destination: 123,
    weight: 0,
    unit: "pounds",
    hazmat: true
  }

what do you expect as output? what do you see?

I am supposed to expect an invalid for containerId, destination as well as units unless the unit property involves the fully spelt out pounds as well instead of just lbs. The output of the code comes out as

{ containerId: 'Invalid',
  destination: 'Invalid',
  unit: 'Invalid' }

What about this instruction?

  • weight: a positive number representing the cargo’s weight.

Happy coding

this one did it thank you so much such a simple mistake!