Tell us what’s happening:
I can not get my code to pass tests 21, 25 and 26. I feel like my outputs are correct so I would like some help please. Thank you
Your code so far
const normalizeUnits = (manifest) => {
const copy = { ...manifest };
if (copy.unit === "lb") {
copy.weight = Math.round(copy.weight * 0.45 * 100) / 100;
copy.unit = "kg";
}
return copy;
};
const validateManifest = (manifest) => {
const errors = {};
if (!("containerId" in manifest)) {
errors.containerId = "Missing";
} else if (!Number.isInteger(manifest.containerId) || manifest.containerId <= 0) {
errors.containerId = "Invalid";
}
if (!("destination" in manifest)) {
errors.destination = "Missing";
} else if (typeof manifest.destination !== "string" || manifest.destination.trim() === "") {
errors.destination = "Invalid";
}
if (!("weight" in manifest)) {
errors.weight = "Missing";
} else if (typeof manifest.weight !== "number" || Number.isNaN(manifest.weight) || manifest.weight <= 0) {
errors.weight = "Invalid";
}
if (!("unit" in manifest)) {
errors.unit = "Missing";
} else if (manifest.unit !== "kg" && manifest.unit !== "lb") {
errors.unit = "Invalid";
}
if (!("hazmat" in manifest)) {
errors.hazmat = "Missing";
} else if (typeof manifest.hazmat !== "boolean") {
errors.hazmat = "Invalid";
}
return errors;
};
const processManifest = (manifest) => {
if (Object.keys(validateManifest(manifest)).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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator