Tell us what’s happening:
I don’t know what’s going on with my code I can’t seem to get my head around it
Your code so far
function normalizeUnits(manifest){
const normalizedManifest = {...manifest};
if(manifest.units === "lb") {
normalizedManifest.weight = manifest.weight * 0.45;
normalizedManifest.unit = "kg";
}
return normalizedManifest;
}
function validateManifest(manifest){
const result = {};
if(manifest.containerId === undefined){
result.containerId = "Missing";
} else if(!Number.isInteger(manifest.containerId) || manifest.containerId <= 0){
result.containerId = "Invalid";
}
if(manifest.destination === undefined){
result.destination = "Missing";
} else if(typeof manifest.destination !== "string" || manifest.destination.trim() === ""){
result.destination = "Invalid";
}
if(manifest.weight=== undefined){
result.weight = "Missing";
} else if(typeof manifest.weight !== "number" || Number.isNaN(manifest.weight) || manifest.weight <= 0){
result.weight = "Invalid";
}
if(manifest.unit === undefined){
result.unit = "Missing";
} else if(manifest.unit !=="kg" && manifest.unit !== "lb"){
result.unit = "Invalid";
}
if (manifest.hamzat === undefined){
result.hamzat = "Missing";
} else if (typeof manifest.hamzat !== "boolean"){
result.hamzat = "Invalid";
}
return result;
}
function processManifest(manifest){
const validationResult = validateManifest(manifest);
if(Object.keys(validationResult).lenght === 0){
console.log(`Validation success:${manifest.containerId}`);
const normalizedManifest = normalizeUnits(manifest);
console.log(`Total weight: ${normalizedManifest.weight} kg`);
}
else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validationResult);
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 Edg/150.0.0.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator