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