Tell us what’s happening:
I’m having issues passing tests 14 and 17-20. I think it might be an issue with the processManifest function, but I’m not sure. I tried making the if condition just the output of the validate function, but that causes other tests to break instead. I would appreciate some guidance.
Your code so far
function normalizeUnits(manifest){
const newMan = {...manifest};
if(newMan.unit === "kg"){
return newMan
}
else{
newMan.weight = newMan.weight * 0.45;
newMan.unit = "kg";
return newMan;
}
}
function validateManifest(manifest){
const newMan = {};
if(!manifest.hasOwnProperty("containerId")){
newMan.containerId = "Missing";
}
else if(typeof manifest.containerId !== "number" || !Number.isInteger(manifest.containerId) || manifest.containerId <= 0){
newMan.containerId = "Invalid";
}
if(!manifest.hasOwnProperty("destination")){
newMan.destination = "Missing";
}
else if(typeof manifest.destination !== "string" ||
manifest.destination.trim() === ""){
newMan.destination = "Invalid";
}
if(!manifest.hasOwnProperty("weight")){
newMan.weight = "Missing";
}
else if(typeof manifest.weight !== "number" ||
Number.isNaN(manifest.weight) ||
manifest.weight < 0){
newMan.weight = "Invalid";
}
if(!manifest.hasOwnProperty("unit")){
newMan.unit = "Missing";
}
else if(typeof manifest.unit !== "string" ||
!["kg", "lb"].includes(manifest.unit.toLowerCase())){
newMan.unit = "Invalid";
}
if(!manifest.hasOwnProperty("hazmat")){
newMan.hazmat = "Missing";
}
else if(typeof manifest.hazmat !== "boolean"){
newMan.hazmat = "Invalid";
}
return newMan;
}
function processManifest(manifest){
if(validateManifest(manifest) === {}){
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));
}
}
processManifest(
{containerId: 55,
destination: "Carmel",
weight: 400,
unit: "lb",
hazmat: false}
);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator