Tell us what’s happening:
the codes are not going through at all , please what are exactly missing??
Your code so far
function normalizedUnits(manifest) {
const normalizedManifest = { ...manifest};
if (normalizedmanifest.unit === "lb") {
normalizedManifest.weight = normalizedManifest.weight * 0.45;
normalizedManifest.unit = "Kg";
}
return normalizedManifest;
}
function validateManifest(manifest) {
const errors = {};
if (! manifest.hasOwnProperty("containerId")) {
errors.containerId = "Missing";
} else if (
! Number.isInteger(manifest.containerId) ||
manifest.containerId < 1
) {
errors.containerId = "Invalid";
}
if (! manifest.hasOwnProperty("destination")) {
errors.destination = "Missing";
} else if (
typeof manifest.destination !== "string" ||
manifest.destination.trim().length === 0
) {
errors.destination = "Invalid";
}
if (! manifest.hasOwnProperty("unit")) {
errors.unit = "Missing";
} else if (
manifest.unit !== "kg" &&
manifest.unit !== "lb"
) {
errors.unit = "Invalid";
}
if (! manifest.hasOWnProperty("weight")) {
errors.weight = "Missing";
} else if (
typeof manifest.weight !== "number" ||
Number.isNaN(manifest.weight) ||
manifest.weight <= 0
) {
errors.weight = "Invalid";
}
if (! manifest.hasOwnProperty("hazmat")) {
errors.hamzat = "Missing";
} else if (typeof manifest.hazmat !== "boolean") {
errors.hazmat = "Invalid";
}
return errors;
}
function processManifest(manifest) {
const errors = validateManifest(manifest);
const isValid = Object.keys(errors).length === 0;
if (isValid) {
const normalized = normalizeUnits(manifest);
console.log(`Validation success: ${normalized.containerId}`);
console.log(`Total weight: ${normalized.weight} kg`);
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(errors);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator