Tell us what’s happening:
Idk where does the undefined log comes from when i call the processManifest function.
the task 7 also failed to registered even though the output its seem correct. help please
Your code so far
const normalizeUnits = manifest => {
//lb ÷ 2.205 = kg
const copy = {...manifest};
if(manifest.unit !== 'kg'){
copy.weight = manifest.weight * 0.45;
copy.unit = "kg";
return copy;
}
else return copy;
}
const validateManifest = manifest => {
let copy = {};
//containerId
if(manifest.containerId === undefined){
copy.containerId = "Missing";
}
else if(Number.isInteger(manifest.containerId) === false || manifest.containerId < 1){
copy.containerId = "Invalid";
};
//destination
if(manifest.destination === undefined){
copy.destination = "Missing";
}
else if(typeof(manifest.destination) !== "string" || manifest.destination.trim() === ""){
copy.destination = "Invalid";
};
//weigt
if(manifest.weight === undefined){
copy.weight = "Missing"
}
else if(Number.isInteger(manifest.weight) === false || manifest.weight < 1){
copy.weight = "Invalid";
};
//unit
if(manifest.unit === undefined){
copy.unit = "Missing";
}
else if(typeof(manifest.unit) !== "string" || manifest.unit !== "kg"){
copy.unit = "Invalid";
};
//hazmat
if(manifest.hazmat === undefined){
copy.hazmat = "Missing";
}
else if(typeof(manifest.hazmat) !== "boolean"){
copy.hazmat = "Invalid";
};
return copy;
}
const processManifest = manifest =>{
let normalize = normalizeUnits(manifest);
// console.log(normalize);
let val = validateManifest(normalize);
// console.log(val);
if (validateManifest(manifest).unit == "Invalid"){
normalize;
if(Object.keys(val).length == 0){
console.log(`Validation success: ${normalize.containerId}`);
console.log(`Total weight: ${normalize.weight} Kg`);
}
else if(Object.keys(val).length > 0){
console.log(`Validation error: ${normalize.containerId}`);
console.log(val);
}
}
else{
console.log(`Validation error: ${manifest.containerId}`);
console.log(val);
}
return;
}
// console.log(normalizeUnits({ containerId: 68, destination: "Salinas", weight: 101, unit: "kg", hazmat: true }));
// console.log(validateManifest({ containerId: 1, destination: "Santa Cruz", weight: 304, unit: "kg", hazmat: false }));
// console.log(validateManifest({ containerId: 0, destination: 405, weight: -84, unit: "pounds", hazmat: "no" }));
// console.log(validateManifest({}))
// console.log(validateManifest({ destination: " " }))
// console.log(processManifest({ containerId: -88, destination: "Soledad", weight: NaN }))
console.log(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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator