Tell us what’s happening:
I cant understand why it doesnt comply to step 15, please explain why
Your code so far
function normalizeUnits (manifest) {
let kgManifest = {...manifest};;
if (manifest.unit == "lb") {
kgManifest.weight = manifest.weight * 0.45;
kgManifest.unit = "kg";
return kgManifest;
} else {
return kgManifest;
}
}
function validateManifest (manifest) {
const wrongList = {};
if (manifest.hasOwnProperty("containerId") == false) {
wrongList.containerId = "Missing";
} else if (!Number.isInteger(manifest.containerId) || manifest.containerId <= 0) {
wrongList.containerId = "Invalid"
}
if (manifest.hasOwnProperty("destination") == false) {
wrongList.destination = "Missing";
} else if (typeof manifest.destination !== 'string') {
wrongList.destination = "Invalid"
} else if (manifest.destination.trim() === "") {
wrongList.destination = "Invalid";
}
if (manifest.hasOwnProperty("weight") == false) {
wrongList.weight = "Missing";
} else if (typeof manifest.weight !== "number" || Number.isNaN(manifest.weight) || manifest.weight < 0) {
wrongList.weight = "Invalid"
}
if (manifest.hasOwnProperty("unit") == false) {
wrongList.unit = "Missing";
} else if (manifest.unit !== "kg" && manifest.unit !== "lb") {
wrongList.unit = "Invalid"
}
if (manifest.hasOwnProperty("hazmat") == false) {
wrongList.hazmat = "Missing";
} else if (typeof manifest.hazmat !== 'boolean') {
wrongList.hazmat = "Invalid"
}
return wrongList;
}
function processManifest (manifest) {
const errors = (validateManifest(manifest));
if (Object.keys(errors).length !== 0) {
console.log(`Validation error: ${manifest.containerId}`);
console.log(errors);
} else {
const normalized = normalizeUnits(manifest);
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${normalized.weight} kg`);
}
}
processManifest({ containerId: -88, destination: "Soledad", weight: NaN, unit: "pound", hazmat: "1" });
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator