Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

I keep getting an error message saying I’m using const on the functions.

Your code so far

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

let validateManifest = (manifest) => {
let errors = { };
if (!manifest.hasOwnProperty("containerId")) {
  errors.containerId = "Missing";
}
if (!manifest.hasOwnProperty("destination")) {
  errors.destination = "Missing";
}   
if (!manifest.hasOwnProperty("weight")) {
  errors.weight = "Missing";
}
if (!manifest.hasOwnProperty("unit")) {
  errors.unit = "Missing";
}
if (!manifest.hasOwnProperty("hazmat")) {
  errors.hazmat = "Missing";
}
if (!Number.isInteger(manifest.containerId) || manifest.containerId <= 0){
errors.containerId = "Invalid";
}
if (!destination.trim() || manifest.destination.trim().length === 0) {
    errors.destination = "Invalid"
}
if (manifest.weight =< 0 || weight.isNaN()) {
  errors.weight = "Invalid";
} 
if (manifest.unit !== "kg" && manifest.unit !== "lb") {
  errors.unit = "Invalid";
}
if (typeof manifest.hazmat !== "boolean") {
errors.hazmat = "Invalid";
}
return errors;
};

let processManifest = (manifest) => {
  const errors = validateManifest(manifest);

  if (Object.keys(errors).length === 0) {
    
    console.log(`Validation success: ${manifest.containerId}`);

    const weightInKg = normalizeUnits(manifest.weight, manifest.unit);

    console.log(`Total weight: ${weightInKg} kg`);
  } else {
  
    console.log(`Validation error: ${manifest.containerId}`);
    console.log(errors);
  }
};





Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36 Edg/153.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

Hi @wredina936,

I’m seeing this syntax error in the console:

SyntaxError: unknown: Unexpected token (36:21)

  34 |     errors.destination = "Invalid"
  35 | }
> 36 | if (manifest.weight =< 0 || weight.isNaN()) {
     |                      ^
  37 |   errors.weight = "Invalid";
  38 | } 
  39 | if (manifest.unit !== "kg" && manifest.unit !== "lb") {

Happy coding

Thanks, I didn’t know what was going on.