Tell us what’s happening:
My function returns an object, but the error in step 14 indicates that it doesn’t.
Your code so far
function normalizeUnits (manifest){
const copia = {...manifest};
if (copia.unit === "lb"){
copia.weight *= 0.45;
copia.unit = "kg";
}
return copia;
}
function validateManifest(manifest) {
const resultado = {};
if (!Object.hasOwn(manifest, "containerId")) {
resultado.containerId = "Missing";
} else if (!Number.isInteger(manifest.containerId) || manifest.containerId < 1) {
resultado.containerId = "Invalid";
} else {
resultado.containerId = manifest.containerId;
}
if (!Object.hasOwn(manifest, "destination")) {
resultado.destination = "Missing";
} else if (typeof manifest.destination !== "string" || manifest.destination.trim() === "") {
resultado.destination = "Invalid";
} else {
resultado.destination = manifest.destination;
}
if (!Object.hasOwn(manifest, "weight")) {
resultado.weight = "Missing";
} else if (typeof manifest.weight !== "number" || Number.isNaN(manifest.weight) || manifest.weight <= 0) {
resultado.weight = "Invalid";
} else {
resultado.weight = manifest.weight;
}
if (!Object.hasOwn(manifest, "unit")) {
resultado.unit = "Missing";
} else if (!(manifest.unit === "kg" || manifest.unit === "lb")) {
resultado.unit = "Invalid";
} else {
resultado.unit = manifest.unit;
}
if (!Object.hasOwn(manifest, "hazmat")) {
resultado.hazmat = "Missing";
} else if (typeof manifest.hazmat !== "boolean") {
resultado.hazmat = "Invalid";
} else {
resultado.hazmat = manifest.hazmat;
}
const todoValido =
Number.isInteger(resultado.containerId) &&
typeof resultado.destination === "string" &&
typeof resultado.weight === "number" &&
(resultado.unit === "kg" || resultado.unit === "lb") &&
typeof resultado.hazmat === "boolean";
return todoValido ? {} : resultado;
}
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