I’ve been stuck on this one for a while. It passes the tests, but says I have a syntax error on line 47.
function normalizeUnits(manifest) {
const newManifest = {...manifest};
if (manifest.unit == "lb") {
newManifest.unit = "kg";
newManifest.weight = manifest.weight * 0.45;
}
return newManifest;
}
function validateManifest(manifest) {
let newManifest= {};
let invalid = false;
if (!Object.hasOwn(manifest, "containerId")) {
invalid = true;
newManifest.containerId = "invalid";
}
}
if(Object.hasOwn(manifest, "destination")) {
invalid = true;
newManifest.destination = "Missing";
} else {
if (Number.isInteger(manifest.destination) || manifest.destination.trim()==="") {
invalid = true;
newManifest.destination = "Invalid";
}
}
if (!Object.hasOwn(manifest, "unit")) {
invalid = true;
newManifest.unit = "Missing";
} else {
if (typeof manifest.unit !== "string" || !["kg", "lb"].includes(manifest.unit.trim().toLowerCase()))
// if ((manifest.unit.trim().toLowerCase() !== "lb" && manifest.unit.trim().toLowerCase()!=="kg"))
{
invalid = true;
manifest.unit = "Invalid";
}
}
if (Object.hasOwn(manifest, "hazmat")) {
invalid = true;
newManifest.hazmat = "Missing";
} else {
if(typeof manifest.hazmat !== "boolean") {
invalid = true;
newManifest.hazmat = "Invalid";
}
if (invalid != true) {
return {...newManifest};
} else {
return {};
}
}
function processManifest(manifest) {
let newManifest = validateManifest(manifest);
if (Object.hasOwn(manifest, "containerId") || Object.hasOwn(manifest, "destination") || !Object.hasOwn(manifest, "weight") || !Object.hasOwn(manifest, "unit") || !Object.hasOwn(manifest, "hazmat"))
{
console.log(`Validation error: ${manifest.containerId}`);
console.log(newManifest);
} else {
console.log(`Validation success: ${manifest.containerId}`);
newManifest = normalizeUnits(manifest);
console.log(`Total weight: ${newManifest.weight} kg`);
}
}
console.log(validateManifest({containerId: 55, destination: "Carmel", weight: .00, unit: "lb", hazmat: false});