Tell us what’s happening:
I can’t seem to pass beyond step 18 and I can’t figure out what is wrong.
When I test the function processManifest agaisnt the console the value undefined always at the end.
Your code so far
const cargo1 = {
containerId: 68,
destination: "Salinas",
weight: 101,
unit: "lb",
hazmat: true
};
const normalizeUnits = (manifest) => {
const copyManifest = {... manifest};
if (copyManifest.unit === "lb") {
copyManifest.unit = "kg";
copyManifest.weight = copyManifest.weight * 0.45;
}
return copyManifest
};
// console.log(cargo1);
const cargo2 = {
containerId: 1,
destination: "Santa Cruz",
weight: 304,
unit: "kg",
hazmat: false
}
const validateManifest = (manifest) => {
const newManifest = {};
if ("containerId" in manifest == false) {
newManifest.containerId = "Missing"
} else if (manifest.containerId == null || manifest.containerId == undefined || manifest.containerId <1 || !Number.isInteger(manifest.containerId)) {
newManifest.containerId = "Invalid"
};
if ("destination" in manifest == false) {
newManifest.destination = "Missing"
} else if (typeof manifest.destination != "string" || manifest.destination.trim() == 0) {
newManifest.destination = "Invalid"
};
if ("weight" in manifest == false) {
newManifest.weight = "Missing"
} else if (Number.isNaN(manifest.weight) || typeof manifest.weight != "number" || manifest.weight<=0) {
newManifest.weight = "Invalid"
};
if ("unit" in manifest == false) {
newManifest.unit = "Missing"
} else if (manifest.unit != "lb" && manifest.unit != "kg") {
newManifest.unit = "Invalid"
};
if ("hazmat" in manifest == false) {
newManifest.hazmat = "Missing"
} else if (typeof manifest.hazmat != "boolean") {
newManifest.hazmat = "Invalid"
};
return newManifest;
};
//console.log(validateManifest(cargo2));
const isEmpty = (manifest) => {
if (Object.keys(validateManifest(manifest)).length === 0) {
return true;
} else {
return false;
}
};
const processManifest = (manifest) => {
if (isEmpty(manifest) === true) {
console.log("Validation success: ${containerId}");
console.log("Total weight: ${normalizeUnits(manifest.weight)} kg");
} else {
console.log("Validation error: ${containerId}");
console.log(validateManifest(manifest));
}
};
const cargo3 = {
containerId: -88,
destination: "Soledad",
weight: NaN
}
console.log(processManifest(cargo3))
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator