Tell us what’s happening:
Test 16 has failed, and it is not possible to reproduce the error without the argument.
Your code so far
function normalizeUnits(manifest){
const newManifest = {...manifest};
if(manifest.unit === "kg"){
return newManifest;
}
if(manifest.unit === "lb"){
newManifest.unit = "kg";
newManifest.weight = manifest.weight * 0.45;
return newManifest;
}
}
function validateManifest(manifest){
const newManifest = {};
if(manifest.hasOwnProperty("containerId")){
if(!Number.isInteger(manifest.containerId) || manifest.containerId <= 0){
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((Number.isNaN(manifest.weight)) || manifest.weight < 0){
newManifest.weight = "Invalid";
}
} else{
newManifest.weight = "Missing";
}
if(manifest.hasOwnProperty("unit")){
if(typeof manifest.unit !== "string" || ((manifest.unit.toLowerCase() != "kg") && (manifest.unit.toLowerCase() != "lb"))){
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){
const valid = validateManifest(manifest);
if(Object.keys(valid).length === 0){
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${normalizeUnits(manifest).weight} kg`);
} else{
console.log(`Validation error: ${manifest.containerId}`);
console.log(validateManifest(manifest));
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator