Tell us what’s happening:
Hi there!
I’m having trouble with test 15 and I don’t know what I’m doing wrong.
Can anyone please give me a hint
Your code so far
function normalizeUnits(manifest) {
let copy = {...manifest}
if (copy.unit === "lb") {
copy.weight *= .45;
copy.unit = "kg"
return copy;
}
return copy;
}
function validateManifest(manifest) {
let copy = {};
if(!(Object.hasOwn(manifest, "containerId"))){
copy.containerId = "Missing";
} else if(typeof manifest.containerId !== 'number' || manifest.containerId <= 0 || manifest.containerId % 1 !== 0) {
copy.containerId = "Invalid";
};
if(!(Object.hasOwn(manifest, "destination"))){
copy.destination = "Missing";
} else if(typeof manifest.destination !== 'string' || manifest.destination.trim() == "") {
copy.destination = "Invalid";
};
if(!(Object.hasOwn(manifest, "weight"))){
copy.weight = "Missing";
} else if(typeof manifest.weight !== 'number' || manifest.weight <= 0 || manifest.weight % 1 !== 0) {
copy.weight = "Invalid";
};
if(!(Object.hasOwn(manifest, "unit"))){
copy.unit = "Missing";
} else if(manifest.unit != 'lb' && manifest.unit != "kg") {
copy.unit = "Invalid";
};
if(!(Object.hasOwn(manifest, "hazmat"))){
copy.hazmat = "Missing";
} else if(manifest.hazmat != true && manifest.hazmat != false) {
copy.hazmat = "Invalid";
};
return copy;
}
function processManifest(manifest) {
const normalizedWeight = normalizeUnits(manifest);
const validatedManifest = validateManifest(manifest);
if(Object.keys(validatedManifest).length === 0) {
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${normalizedWeight.weight} kg`)
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validatedManifest);
}
}
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/147.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator