Tell us what’s happening:
My code isn’t working, but I’m not sure why? Stuck at step 14, specifically, the other stuff I’ll debug on my own. Hven’t gotten anything helpful from console.log().
Your code so far
function normalizeUnits(manifest) {
const copy = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.weight,
unit: manifest.unit,
hazmat: manifest.hazmat
}
if(manifest.unit === 'lb') {
copy.weight *= 0.45
copy.unit = 'kg'
}
return copy
}
function validateManifest(manifest) {
const copy = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.weight,
unit: manifest.unit,
hazmat: manifest.hazmat
}
let pass = true;
if(manifest.containerId === undefined || Object.hasOwn(manifest, 'containerId') === false) {
copy.containerId = 'Missing'
pass = false;
}
else if(manifest.containerId <= 0 || typeof manifest.containerId !== 'number' || Number.isInteger(manifest.containerId) === false) {
copy.containerId = 'Invalid';
pass = false;
}
if(manifest.destination === undefined || Object.hasOwn(manifest, 'destination') === false) {
copy.destination = 'Missing';
pass = false;
}
else if(typeof manifest.destination !== 'string' || manifest.destination.trim() === '') {
copy.destination = 'Invalid'
pass = false;
}
if(typeof manifest.weight === undefined || Object.hasOwn(manifest, 'weight') === false) {
copy.weight = 'Missing';
pass = false;
}
else if(typeof manifest.weight !== 'number' || manifest.weight < 1 || Number.isNaN(manifest.weight)) {
copy.weight = 'Invalid';
pass = false;
}
if(typeof manifest.unit === undefined || Object.hasOwn(manifest, 'unit') === false) {
copy.unit = 'Missing';
pass = false;
}
else if(manifest.unit !== 'kg' && manifest.unit !== 'lb') {
copy.unit = 'Invalid';
pass = false;
}
if(typeof manifest.hazmat === undefined || Object.hasOwn(manifest, 'hazmat') === false) {
copy.hazmat = 'Missing';
pass = false;
}
else if(typeof manifest.hazmat !== 'boolean') {
copy.hazmat = 'Invalid';
pass = false;
}
if(pass) {
return {}
}
else {
return copy
}
}
function processManifest(manifest) {
if(validateObject(manifest) === {}) {
console.log(`Validation success: ${containerId}`);
console.log(`Total weight: ${normalizeUnits(manifest)} kg`);
}
else {
console.log(`Validation error: ${containerId}`);
console.log(validateManifest(manifest));
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 OPR/128.0.0.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator