Tell us what’s happening:
getting stuck on no.16 and 1, havent used const but think thats just a testing bug, 16 not sure how else to test it, no syntax or logic failures
Your code so far
function normalizeUnits(manifest) {
let copy = {...manifest}
if (copy.unit === "lb") {
let newWeight = copy.weight * 0.45;
copy.weight = newWeight;
copy.unit = "kg";
} else {
return copy;
}
return copy;
}
function validateManifest(manifest) {
let errors = {};
if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) {
return { manifest: "Invalid input type. Must be an object." };
}
if (!manifest.hasOwnProperty("containerId")) {
errors.containerId = "Missing";
}else if (manifest.containerId === null || manifest.containerId <= 0 || typeof manifest.containerId !== "number" || !Number.isInteger(manifest.containerId)) {
errors.containerId = "Invalid";
}
if (!manifest.hasOwnProperty("destination")) {
errors.destination = "Missing";
} else if (typeof manifest.destination !== "string" || manifest.destination.trim() === "") {
errors.destination = "Invalid";
}
if (!manifest.hasOwnProperty("weight")) {
errors.weight = "Missing";
} else if (
typeof manifest.weight !== "number" || !Number.isFinite(manifest.weight) ||
manifest.weight < 0) {
errors.weight = "Invalid";
}
if (!manifest.hasOwnProperty("unit")) {
errors.unit = "Missing";
} else if (
typeof manifest.unit !== "string" ||
!["lb", "kg"].includes(manifest.unit.toLowerCase())
) {
errors.unit = "Invalid";
}
if (!manifest.hasOwnProperty("hazmat")) {
errors.hazmat = "Missing";
} else if (typeof manifest.hazmat !== "boolean") {
errors.hazmat = "Invalid";
}
return errors;
}
console.log(validateManifest({ containerId: -6,
destination: 123,
weight: 0,
unit: 'pounds',
hazmat: true }))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator