Tell us what’s happening:
test 15 failed, although my function returns a object with the describing missing and/or invalid properties.
Your code so far
function validateManifest(manifest) {
let result = {};
const missing = "Missing";
const invalid = "Invalid";
if (manifest.hasOwnProperty("containerId")) {
if (manifest.containerId <= 0 || manifest.manifestId === null || manifest.containerId % 1 != 0) {
result.containerId = invalid;
}
} else {
result.containerId = missing;
}
if (manifest.hasOwnProperty("destination")) {
if (typeof (manifest.destination) != "string" || manifest.destination.trim() == "") {
result.destination = invalid;
}
} else {
result.destination = missing;
}
if (manifest.hasOwnProperty("weight")) {
if (typeof (manifest.weight) != "number" || manifest.weight <= 0 || isNaN(manifest.weight)) {
result.weight = invalid;
}
} else {
result.weight = missing;
}
if (manifest.hasOwnProperty("unit")) {
if (manifest.unit != "lb" && manifest.unit != "kg") {
result.unit = invalid;
}
} else {
result.unit = missing;
}
if (manifest.hasOwnProperty("hazmat")) {
if (manifest.hazmat != true && manifest.hazmat != false) {
result.hazmat = invalid;
}
} else {
result.hazmat = missing;
}
return result;
}
const test = validateManifest({ destination: "Watsonville", hazmat: true });
console.log(typeof(test));
console.log(test);
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 Edg/146.0.0.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator