Tell us what’s happening:
I having a hard time in correcting number 7 though my code is working
Your code so far
function normalizeUnits(manifest){
let copy = {...manifest}
if(copy.unit.trim() == "lb"){
copy.weight *= 0.45
copy.unit = "kg"
}
return copy
}
console.log(normalizeUnits({
containerId: 68,
destination: "Salinas",
weight: 101,
unit: " lb ",
hazmat: true
}))
console.log('\n');
function validateManifest(manifest){
const requiredFields = {
containerId: v => Number.isInteger(v) && v > 0,
destination: v => typeof v === 'string' && v.trim() !== '',
weight: v => typeof v === 'number' && v > 0,
unit: v => typeof v === 'string' && v.trim() == "kg",
hazmat: v => typeof v === 'boolean'
}
let copy = {...manifest}; let result = {}; let valid = true
for(let key in requiredFields){
let value = copy[key];
if (value === undefined) {
result[key] = 'Missing'; valid = false; continue;
} else if (!requiredFields[key](value)) {
result[key] = 'Invalid';
valid = false
}
}return valid ? {} : result
}
console.log(validateManifest({
containerId: 1, destination: "Salinas", weight: 101, unit: " kg",hazmat: true
}));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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