Tell us what’s happening:
I do not understand why my processManifest function isnt passing checks 17-25.
The logs appear correct in the console but I cant see what I am missing here.
Your code so far
function normalizeUnits (manifest) {
let copy = {...manifest};
if (copy.unit === 'lb') {
copy.unit = "kg";
copy.weight = copy.weight * 0.45;
console.log(copy);
return copy;
};
return copy
};
function validateManifest(manifest) {
let validatedManifest = {}
if (manifest.containerId < 1 || !Number.isInteger (manifest.containerId)) {
validatedManifest.containerId = "Invalid"
console.log(validatedManifest.containerId)
}
if (typeof manifest.destination != "string" || manifest.destination.trim() === "" ) {
validatedManifest.destination = "Invalid"
console.log(validatedManifest.destination)
}
if (typeof manifest.weight != "number" || Number.isNaN(manifest.weight) || manifest.weight < 1 ) {
validatedManifest.weight = "Invalid"
console.log(validatedManifest.weight)
}
if (manifest.unit !== "kg" && manifest.unit !== "lb") {
validatedManifest.unit = "Invalid"
console.log(validatedManifest.unit)
}
if (typeof manifest.hazmat !== "boolean" ) {
validatedManifest.hazmat = "Invalid"
}
let requiredProperties = ["containerId", "destination", "weight", "unit", "hazmat"];
for (const element of requiredProperties) {
if (!manifest.hasOwnProperty(element) || !manifest.hasOwnProperty(element) === " ") {
validatedManifest[element] = "Missing"
}
}
return validatedManifest;
};
function processManifest(manifest) {
let validatedManifest = validateManifest(manifest);
let invalidKeys = Object.keys(validatedManifest)
if (invalidKeys.length === 0) {
let normalizedManifest = normalizeUnits(manifest);
console.log(`Validation success: ${manifest.containerId}`)
console.log(`Total weight: ${normalizedManifest.weight} kg`)
}
else {
console.log(`Validation error: ${manifest.containerId}`)
console.log(validatedManifest)
}
}
processManifest({ containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false })
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator