Tell us what’s happening:
help solve this issue, I am getting confuse to solve this problem
Your code so far
const normalizeUnits = (manifest) => {
let copyManifest = {...manifest}
if(copyManifest.unit === "lb") {
copyManifest.weight = copyManifest.weight * 0.45
copyManifest.unit = "kg"
return copyManifest
} else {
return copyManifest
}
}
console.log(normalizeUnits({ containerId: 68, destination: "Salinas", weight: 506, unit: "kg", hazmat: true }))
// validation manifest object ------------------------------------>
function validateManifest (manifest) {
let input = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.weight,
unit: manifest.unit,
hazmat: manifest.hazmat
}
if (Object.hasOwn(manifest,"containerId")){
if (manifest.containerId === null || manifest.containerId === undefined) {
input.containerId = "Missing"
return input
} else if (!Number.isInteger(manifest.containerId) || manifest.containerId < 1){
input.containerId = "Invalid"
return input
}
}
if (Object.hasOwn(manifest,"destination")){
if (manifest.destination === null || manifest.destination === undefined) {
input.destination = "Missing"
return input
} else if (typeof (manifest.destination) !== "string"){
input.destination = "Invalid"
return input
}
} else {return {}}
if (Object.hasOwn(manifest,"weight")){
if (manifest.weight === null || manifest.weight === undefined) {
input.weight = "Missing"
return input
} else if (!Number.isInteger(manifest.weight) || manifest.weight < 1) {
input.weight = "Invalid"
return input
}
} else {return {}}
if(Object.hasOwn(manifest,"unit")) {
if (
manifest.unit === null || manifest.unit === undefined) {
input.unit = "Missing"
return input
} else if ( manifest.unit !== "kg" || manifest.unit !== "lb") {
input.unit = "Invalid"
return input
}
} else {return {}}
if (Object.hasOwn(manifest, "hazmat")) {
if (manifest.hazmat === null || manifest.hazmat === undefined){
input.hazmat = "Missing";
return input
} else if(typeof(hazmat) !== "boolean") {
input.hazmat = "Invalid";
return input
}
} else {return {}}
}
// console.log(validateManifest({containerId:NaN}))
console.log(validateManifest({ containerId: 100, destination:"santiago", weight:100, unit: 'kg', hazmat: true }))
// process unit manifest object
function processUnit(manifest){
function processManifest(manifest) {
let objWeight = normalizeUnits(manifest);
let validation = validateManifest(manifest);
if (Object.keys(manifest).length < 5) {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validation);
} else {
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${objWeight.weight} kg`);
}
}
console.log(validateManifest({ containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false }))
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) 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