Tell us what’s happening:
I can’t seem to pass test #15 though i am returning an object
Your code so far
function validateManifest (manifest) {
const valideObj = {};
if (manifest.containerId === undefined){
//console.log(manifest.containerId)
valideObj.containerId = "Missing";
} else if (typeof(manifest.containerId) !== "number" || manifest.containerId <= 0 || !Number.isInteger(manifest.containerId) || Number.isNaN(manifest.containerId)){
valideObj.containerId = "Invalid";
}
//console.log(manifest.destination.trim() === "")
if (manifest.destination === undefined){
valideObj.destination = "Missing";
} else if ( typeof(manifest.destination) !== "string"|| manifest.destination.trim() === ""){
valideObj.destination = "Invalid";
}
//console.log(typeof(manifest.destination))
if (manifest.weight === undefined){
valideObj.weight = "Missing";
} else if ( typeof(manifest.weight) !== "number" || manifest.weight <= 0 || Number.isNaN(manifest.weight) ){
valideObj.weight = "Invalid";
}
if (manifest.unit === undefined){
valideObj.unit = "Missing";
} else if (typeof(manifest.unit) !== "string" || manifest.unit.length > 2 || manifest.unit.trim() === ""){
valideObj.unit = "Invalid";
}
// console.log(typeof(""))
if (manifest.hazmat === undefined){
valideObj.hazmat = "Missing";
} else if (typeof(manifest.hazmat) !== "boolean"){
valideObj.hazmat = "Invalid";
}
//console.log(manifest)
return valideObj;
}
const processManifest = manifest => {
const validatedManifest = validateManifest(manifest);
if (Object.keys(validatedManifest).length === 0) {
const 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);
}
}
console.log(validateManifest({ containerId: 1, destination: "Santa Cruz", weight: 304, unit: "kg", hazmat: null }))
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:149.0) Gecko/20100101 Firefox/149.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator