Tell us what’s happening:
Console shows correct results yet tests won’t let me pass
Your code so far
const end = {
containerId: 1,
destination: "Monterey, California, USA",
weight: 831,
unit: "lb",
hazmat: false
}
function normalizeUnits(manifest) {
let {containerId, destination, weight, unit, hazmat} = manifest;
if (unit === "lb") {
unit = "kg"
weight = weight * 0.45
}
const newman = Object.create(manifest)
newman.containerId = containerId
newman.destination = destination
newman.unit = unit
newman.weight = weight
newman.hazmat = hazmat
return newman
}
function validateManifest(manifest) {
let {containerId, destination, weight, unit, hazmat} = manifest;
const newman = Object.create(manifest)
if (Object.hasOwn(manifest, containerId)) {
newman.containerId = "Missing"
} if (Object.hasOwn(manifest, destination)) {
newman.destination = "Missing"
} if (Object.hasOwn(manifest, weight)) {
newman.weight = "Missing"
} if (Object.hasOwn(manifest, unit)) {
newman.unit = "Missing"
} if (Object.hasOwn(manifest, hazmat)) {
newman.hazmat = "Missing"
} else if (Number.isInteger(containerId) === false || containerId < 1) {
newman.containerId = "Invalid"
} else if (String.prototype.trim(destination) == true) {
newman.destination = "Invalid"
} else if (Number.isNaN(weight)) {
newman.weight = "Invalid"
} else if (Object.hasOwn(manifest, hazmat) && unit !== "lb" || Object.hasOwn(manifest, hazmat) && unit !== "kg") {
newman.unit = "Invalid"
} else if (Object.hasOwn(manifest, hazmat) && hazmat !== true || Object.hasOwn(manifest, hazmat) && hazmat !== false) {
newman.hazmat = "Invalid"
}
return newman
}
function processManifest(manifest) {
let {containerId, destination, weight, unit, hazmat} = manifest;
if (validateManifest(manifest) == {}) {
console.log(`Validation success: ${containerId}`)
normalizeUnits(manifest)
console.log(`Total weight: ${weight} kg`)
} else {
console.log(`Validation error: ${containerId}`)
console.log(validateManifest())
}
}
console.log(normalizeUnits({ containerId: 68, destination: "Salinas", weight: 101, unit: "lb", hazmat: true }))
console.log(validateManifest({ containerId: 1, destination: "Santa Cruz", weight: 304, unit: "kg", hazmat: false }))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36 OPR/133.0.0.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator