Tell us what’s happening:
Getting error on 2.6, and 18. It says i dont have function named normalizeUnits, validateManifest and processManifest with param manifest.
Your code so far
function normalizeUnits(manifest ) {
var newObj = {...manifest};
if(newObj.unit !== undefined && newObj.unit == "lb" && newObj.weight !== undefined) {
newObj.weight = manifest.weight * 0.45;
newObj.unit = "kg";
}
return newObj;
}
function validateManifest(manifest) {
var newObj = {};
if (!Object.hasOwn(manifest, 'containerId') || manifest.containerId == 'Missing') {
newObj.containerId = 'Missing';
}
if (!Object.hasOwn(manifest, 'destination') || manifest.destination == 'Missing') {
newObj.destination = 'Missing';
}
if (!Object.hasOwn(manifest, 'weight') || manifest.weight == 'Missing') {
newObj.weight = 'Missing';
}
if (!Object.hasOwn(manifest, 'unit') || manifest.unit == 'Missing') {
newObj.unit = 'Missing';
}
if (!Object.hasOwn(manifest, 'hazmat') || manifest.hazmat == 'Missing') {
newObj.hazmat = 'Missing';
}
if ((!manifest.containerId || manifest.containerId <= 0 || !Number.isInteger(manifest.containerId)) && !Object.hasOwn(newObj, "containerId")) {
newObj.containerId = 'Invalid';
}
if ((!manifest.weight || manifest.weight <= 0) && !Object.hasOwn(newObj, 'weight')) {
newObj.weight = 'Invalid';
}
var allowedUnit = ['kg', 'lb'];
if ((!manifest.unit || !allowedUnit.includes(manifest.unit)) && !Object.hasOwn(newObj, 'unit')) {
newObj.unit = 'Invalid';
}
if ((typeof manifest.hazmat !== 'boolean') && !Object.hasOwn(newObj, 'hazmat')) {
newObj.hazmat = 'Invalid';
}
if ((typeof manifest.destination !== 'string' || manifest.destination?.trim() === "") && !Object.hasOwn(newObj, 'destination')) {
newObj.destination = 'Invalid';
}
return newObj;
}
function processManifest(manifest) {
var validate = validateManifest(manifest);
if (Object.keys(validate).length === 0) {
console.log(`Validation success: ${manifest.containerId}`);
var weight = normalizeUnits(manifest).weight;
console.log(`Total weight: ${weight} kg`);
} else {
console.log(`Validation error: ${manifest.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/151.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator