Tell us what’s happening:
Hello
I am stuck on step 14. “If the input manifest object is not valid, your validateManifest function should return an object describing missing and/or invalid properties.” It seems to me that It is working also I have all the steps from before completed. Would love some guidance.
Your code so far
function normalizeUnits(manifest) {
let copy = {... manifest};
if (copy.unit == "lb") {
copy.weight = (copy.weight) * 0.45;
copy.unit = "kg";
}
return copy;
}
function validateManifest(manifest) {
let copy = {containerId: manifest.containerId, destination: manifest.destination, weight: manifest.weight, unit: manifest.unit, hazmat: manifest.hazmat}
if (copy.containerId === undefined) {
copy.containerId = "Missing";
} else if (copy.containerId > 0 && copy.containerId % 1 ==0) {
delete copy.containerId;
} else
copy.containerId = "Invalid";
if (copy.destination === undefined) {
copy.destination = "Missing";
} else if (typeof copy.destination == "string") {
if (copy.destination.trim() == "") {
copy.destination = "Invalid";
} else
delete copy.destination;
} else
copy.destination = "Invalid";
if (copy.weight === undefined) {
copy.weight = "Missing";
} else if (copy.weight > 0) {
delete copy.weight;
} else
copy.weight = "Invalid";
if (copy.unit === undefined) {
copy.unit = "Missing";
} else if (copy.unit == "kg" || copy.unit == "lb") {
delete copy.unit;
} else
copy.unit = "Invalid";
if (copy.hazmat === undefined) {
copy.hazmat = "Missing";
} else if (copy.hazmat == true || copy.hazmat == false) {
delete copy.hazmat;
} else
copy.hazmat = "Invalid"
return copy;
}
console.log(validateManifest({ destination: " " }));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator