Tell us what’s happening:
I am puzzled in how/why my already saved code for this lab (I hope anyone helping me can check it out) is unable to pass the test #16 “validateManifest function should return an object” but it shows as passed all the others. Unfortunately there is not much description in the actual test #16 in order to debug more accurately.
Your code so far
function normalizeUnits (manifest) {
let normMani = {...manifest};
if (normMani.unit === "lb") {
normMani.weight *= 0.45;
normMani.unit = "kg";
}
return normMani;
};
function validateManifest (manifest) {
let repMani = {};
if (!(typeof manifest === "object")) {
repMani.containerId = "Missing";
repMani.destination = "Missing";
repMani.weight = "Missing";
repMani.unit = "Missing";
repMani.hazmat = "Missing";
return repMani;
}
if (!manifest.hasOwnProperty("containerId")){
repMani.containerId = "Missing";
} else if (!(typeof manifest.containerId === "number" &&
Number.isInteger(manifest.containerId) &&
manifest.containerId > 0)) {
repMani.containerId = "Invalid";
}
if (!manifest.hasOwnProperty("destination")) {
repMani.destination = "Missing";
} else if (!(typeof manifest.destination === "string" && manifest.destination.trim() !== "")) {
repMani.destination = "Invalid";
}
if (!manifest.hasOwnProperty("weight")) {
repMani.weight = "Missing";
} else if (!(typeof manifest.weight === "number" && manifest.weight >= 0)) {
repMani.weight = "Invalid";
}
if (!manifest.hasOwnProperty("unit")) {
repMani.unit = "Missing";
} else if (!(typeof manifest.unit === "string" && (manifest.unit === "kg" || manifest.unit === "lb"))) {
repMani.unit = "Invalid";
}
if (!manifest.hasOwnProperty("hazmat")) {
repMani.hazmat = "Missing";
} else if (!(typeof manifest.hazmat === "boolean")) {
repMani.hazmat = "Invalid";
}
return repMani;
};
function processManifest (manifest) {
let probeMani = validateManifest(manifest);
if (probeMani.hasOwnProperty("containerid") ||
probeMani.hasOwnProperty("destination") ||
probeMani.hasOwnProperty("weight") ||
probeMani.hasOwnProperty("unit") ||
probeMani.hasOwnProperty("hazmat")) {
console.log(`Validation error: ${manifest.containerId}`);
console.log(probeMani);
} else {
let normMani = normalizeUnits(manifest);
console.log(`Validation success: ${normMani.containerId}`);
console.log(`Total weight: ${normMani.weight} kg`);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:154.0) Gecko/20100101 Firefox/154.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator