Tell us what’s happening:
Im stuck on step number 8 an d cant seem to figure out why
Your code so far
const normalizeUnits = function(manifest){
const manifestCopy = {...manifest};
if(manifestCopy.unit === "lb"){
manifestCopy.unit = "kg";
manifestCopy.weight = manifest.weight * 0.45;
}
return manifestCopy
}
function validateManifest(manifest) {
const errors = {};
const required = ["containerId", "destination", "weight", "unit", "hazmat"];
required.forEach(prop => {
if (!(prop in manifest)) {
errors.prop = "Missing";
}
});
if (manifest.weight !== undefined && (typeof manifest.weight !== "number" || manifest.weight < 0)) {
errors.weight = "Invalid";
}
if(typeof manifest.hazmat !== "boolean"){
errors.hazmat = "Invalid";
}
return errors;
}
function processManifest(manifest) {
const errors = validateManifest(manifest);
const isValid = Object.keys(errors).length === 0;
if (isValid) {
const normalized = normalizeUnits(manifest);
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${normalized.weight} kg`);
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(errors);
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator