Tell us what’s happening:
I am working on the Cargo Manifest Validator lab and although the functional requirements pass, the process ones will not and I have no idea why. I keep getting this message:
If the input manifest object is valid, your processManifest function should log a success message with the object’s containerId, and then log the object’s weight in kilograms. You should use normalizeUnits() for the conversion and have two console.log() calls.
Your code so far
const normalizeUnits = (manifest) => {
const newManifest = {...manifest};
if(newManifest.unit === "lb") {
newManifest.unit = "kg";
newManifest.weight *= 0.45;
return newManifest;
}
return newManifest;
}
const validateManifest = (manifest) => {
const containerId = manifest.containerId;
const destination = manifest.destination;
const weight = manifest.weight;
const unit = manifest.unit;
const hazmat = manifest.hazmat;
const validatedManifest = {};
if(containerId === undefined) {
validatedManifest.containerId = "Missing";
} else if (containerId <= 0 || typeof(containerId) != 'number' ||
!Number.isInteger(containerId) || Number.isNaN(containerId)) {
validatedManifest.containerId = "Invalid";
}
if (destination === undefined )
{
validatedManifest.destination = "Missing";
} else if (typeof(destination) !== 'string' || destination.trim() === "") {
validatedManifest.destination = "Invalid";
}
if(weight === undefined) {
validatedManifest.weight = "Missing";
} else if (weight <= 0 || typeof(weight) != 'number' ||
Number.isNaN(weight)) {
validatedManifest.weight = "Invalid";
}
if((typeof(unit) === 'string' && unit.trim() === "") ||
unit === undefined) {
validatedManifest.unit = "Missing";
} else if (unit !== "lb" && unit !== "kg" ) {
validatedManifest.unit = "Invalid";
}
if(hazmat === undefined) {
validatedManifest.hazmat = "Missing";
} else if (hazmat !== true && hazmat !== false ) {
validatedManifest.hazmat = "Invalid";
}
return validatedManifest;
}
const processManifest = (manifest) => {
//const manifestValid = validateManifest(manifest);
if(Object.keys(validateManifest(manifest)).length === 0) {
console.log(`Validation success: ${manifest.containerId}`);
const normalized = normalizeUnits(manifest);
//const weight = normalizeUnits(manifest).weight;
console.log(`Total weight: ${normalized.weight} ${normalized.unit}`);
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validateManifest(manifest));
}
}
const myManifest = { containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false };
processManifest(myManifest);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator