Hello,
All tests except for 14 ( 14. If the input manifest object is not valid, your validateManifest
function should return an object describing missing and/or invalid properties.) are passing. Would you give me a hint?
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 = "Missing";
}
else {
if (typeof manifest.containerId !=="number" || !Number.isInteger(manifest.containerId) || manifest.containerId <= 0) {
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, "weight")) {
invalid = true;
newManifest.weight = "Missing";
}
else {
if(typeof manifest.weight !=="number" || Number.isNaN(manifest.weight) || manifest.weight <= 0) {
invalid = true;
newManifest.weight = "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;
newManifest.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)
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 }));