Tell us what’s happening:
Can someone please help me understand what i am doing wrong, i have been at it for a week now and i cannot pass step 9
do not tell me the answer, just tell me the problem
Your code so far
const cargoManifest = {
containerId: 1,
destination: "Monterey, California, USA",
weight: 831,
unit: "lb",
hazmat: false
};
const normalizeUnits = (manifest) => {
const newManifest = {...manifest};
if (newManifest.unit === "lb") {
newManifest.weight = Number((newManifest.weight * 0.45).toFixed(2));
newManifest.unit = "kg";
console.log(`unit conversion made - newManifest.weight from lb to kg`);
return newManifest;
} else if (newManifest.unit == 'kg'){
console.log();
return newManifest;
}
return manifest
};
console.log(normalizeUnits({
containerId: 1,
destination: "Monterey, California, USA",
weight: 80,
unit: "lb",
hazmat: true
}));
//Validate Manifest section
const validateManifest = (manifest) => {
const newValidation = {...manifest};
newValidation.containerId = ("containerId" in newValidation && typeof newValidation.containerId === "number") ? newValidation.containerId : ("containerId" in newValidation && typeof newValidation.containerId !== "number") ? "Invalid" : "Missing";
newValidation.destination = ("destination" in newValidation && typeof newValidation.destination === "string") ? newValidation.destination : ("destination" in newValidation && typeof newValidation.destination !== "string") ? "Invalid" : "Missing";
newValidation.weight = ("weight" in newValidation && typeof newValidation.weight === "number") ? newValidation.weight : ("weight" in newValidation && typeof newValidation.weight !== "number") ? "invalid" : "Missing";
newValidation.unit = ("unit" in newValidation && typeof newValidation.unit === "string") ? newValidation.unit : ("unit" in newValidation && typeof newValidation.unit !== "string") ? "Invalid" : "Missing";
newValidation.hazmat = ("hazmat" in newValidation && typeof newValidation.hazmat === "boolean") ? newValidation.hazmat : ("hazmat" in newValidation && typeof newValidation.hazmat !== "boolean") ? "Invalid" : "Missing";
if ("containerId" in newValidation && typeof newValidation.containerId === "number"
&&
"destination" in newValidation && typeof newValidation.destination === "string"
&&
"weight" in newValidation && typeof newValidation.weight === "number"
&&
"unit" in newValidation && typeof newValidation.unit === "string"
&&
"hazmat" in newValidation && typeof newValidation.hazmat === "boolean") {
return new Object();
}
return newValidation
};
console.log(validateManifest({containerId: null, destination: 22, weight: "yac", unit: "lb", hazmat: true }));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator