I have a problem with Step 15: Kindly help me check my code or give me a hint!
Thanks a lot! loving the learning journey.
function validateManifest(manifest){
const copy = {...manifest};
const errors = {};
if (typeof copy !== "object") {
errors.containerId = "Invalid";
errors.destination = "Invalid";
errors.weight = "Invalid";
errors.unit = "Invalid";
errors.hazmat = "Invalid";
}
if(!copy.hasOwnProperty("containerId") || copy.containerId === ""){
errors.containerId = "Missing";
}else if(
copy.containerId === null ||
copy.containerId <= 0 ||
isNaN(copy.containerId)
){ errors.containerId = "Invalid";
}else if(!Number.isInteger(copy.containerId)){
errors.containerId = "Invalid";
errors.destination = "Missing";
errors.weight = "Missing";
errors.unit = "Missing"
errors.hazmat = "Missing";
};
if(!copy.hasOwnProperty("destination") ||
copy.destination === "")
{
errors.destination = "Missing"
}
else if(typeof copy.destination !== "string" || copy.destination.trim() === ""){
errors.destination = "Invalid";
};
if(!copy.hasOwnProperty("weight") || copy.weight === ""){
errors.weight = "Missing"
}else if(typeof copy.weight !== "number" || copy.weight < 0 || isNaN(copy.weight)){
errors.weight = "Invalid";
};
if(!copy.hasOwnProperty("unit") || copy.unit === ""){
errors.unit = "Missing"
}else if(copy.unit !== "kg" && copy.unit !== "lb" || typeof copy.unit !== "string"){
errors.unit = "Invalid";
};
if(!copy.hasOwnProperty("hazmat") || copy.hazmat === ""){
errors.hazmat = "Missing"
}else if(typeof copy.hazmat !== "boolean"){
errors.hazmat = "Invalid";
};
return errors;
};
console.log(validateManifest(123));