Tell us what’s happening:
i wonder why my code fails at test 15. can you tell me what went wrong? thanks in advance
Your code so far
const normalizeUnits = (manifest) => {
let manifestCopy = { ...manifest }
if (manifest.unit === "lb") {
manifestCopy.weight = manifest.weight * 0.45
manifestCopy.unit = "kg"
return manifestCopy
}
return manifestCopy
}
const validateManifest = (manifest) => {
let manifestCopy = { ...manifest }
let invalidEntry = {}
// id
if (Object.hasOwn(manifestCopy, "containerId")) {
if (typeof manifestCopy.containerId === "number") {
if (manifestCopy.containerId <= 0
|| !Number.isInteger(manifestCopy.containerId)) {
invalidEntry.containerId = "Invalid"
}
} else {
invalidEntry.containerId = "Invalid"
}
} else {
invalidEntry.containerId = "Missing"
}
// destination
if (Object.hasOwn(manifestCopy, "destination")) {
if (typeof manifestCopy.destination === "string") {
if (manifestCopy.destination.trim() === "") {
invalidEntry.destination = "Invalid"
}
} else {
invalidEntry.destination = "Invalid"
}
} else {
invalidEntry.destination = "Missing"
}
// weight
if (Object.hasOwn(manifestCopy, "weight")) {
if (typeof manifestCopy.weight === "number") {
if (manifestCopy.weight < 0
|| Number.isNaN(manifestCopy.weight)) {
invalidEntry.weight = "Invalid"
}
} else {
invalidEntry.weight = "Invalid"
}
} else {
invalidEntry.weight = "Missing"
}
// unit
if (Object.hasOwn(manifestCopy, "unit")) {
if (typeof manifestCopy.unit === "string") {
if (manifestCopy.unit !== "lb" && manifestCopy.unit !== "kg") {
invalidEntry.unit = "Invalid"
}
} else {
invalidEntry.unit = "Invalid"
}
} else {
invalidEntry.unit = "Missing"
}
// hazmat
if (Object.hasOwn(manifestCopy, "hazmat")) {
if (typeof manifestCopy.hazmat === "boolean") {
null
} else {
invalidEntry.hazmat = "Invalid"
}
} else {
invalidEntry.hazmat = "Missing"
}
return invalidEntry
}
// You should implement a function named processManifest with a manifest parameter. The function should log:
// If the manifest object is valid, Validation success: ${containerId} and then the manifest's weight in kilograms as such, Total weight: ${weight} kg. Use normalizeUnits() for this conversion.
// If the manifest object is not valid, Validation error: ${containerId} and then the object returned by calling validateManifest() with the manifest object.
// Note: each of these two cases should have two console.log() calls.
const processManifest = manifest => {
}
// console.log(processManifest({ containerId: -88, destination: "Soledad", weight: NaN }))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator