It’s telling me that I should get a specific output (with all keys missing) when I put in an empty object ({}). I’m getting that when I console.log but it’s not letting me pass. Help?
function normalizeUnits(manifest) {
let copy = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.unit === "kg" ? manifest.weight : Number(parseFloat(manifest.weight * 0.45)),
unit: "kg",
hazmat: manifest.hazmat
};
return copy;
}
function validateManifest(manifest){
let copy = {};
console.log(manifest.unit);
if (manifest.containerId === undefined) {
copy.containerId = "Missing";
} else if (typeof(manifest.containerId) !== "number") {
copy.containerId = "Invalid";
}
if (manifest.destination === undefined) {
copy.desination = "Missing";
} else if (typeof(manifest.destination) !== "string") {
copy.destination = "Invalid";
}
if (manifest.weight === undefined) {
copy.weight = "Missing";
} else if (typeof(manifest.weight) !== "number") {
copy.weight = "Invalid";
}
if (manifest.unit === undefined) {
copy.unit = "Missing";
} else if (manifest.unit !== "lb" && manifest.unit !== "kg") {
copy.unit = "Invalid";
}
if (manifest.hazmat === undefined) {
copy.hazmat = "Missing";
} else if (typeof(manifest.hazmat) !== "boolean") {
copy.hazmat = "Invalid";
}
return copy;
}
const object = {
containerId: 68,
destination: "Salinas",
weight: 101,
unit: "lb",
hazmat: true
}
const objectTwo = {};
console.log(validateManifest(objectTwo));
dhess
May 30, 2026, 6:10pm
2
Welcome to the forum @besaidaurochs07 ,
Here’s an excerpt from the instructions:
containerId: a positive integer identifying the associated cargo container.
weight: a positive number representing the cargo’s weight.
Is zero a positive number? Can containerId be any type of number?
You should have more validation checks for invalid values. Use what the tests expect to help you.
Edit:
[quote="besaidaurochs07, post:1, topic:790294"]
` copy.desination = "Missing";`
[/quote]
You have a typo.
Happy coding
Thanks so much for the help! The typo was what was doing it.
I’m still having trouble though. It says processManifest isn’t producing the right output even though the console log says it is? Here’s the code.
function normalizeUnits(manifest) {
let copy = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.unit === "kg" ? manifest.weight : Number(parseFloat(manifest.weight * 0.45)),
unit: "kg",
hazmat: manifest.hazmat
};
return copy;
}
function validateManifest(manifest){
let copy = {};
//console.log(manifest.unit);
if (manifest.containerId === undefined) {
copy.containerId = "Missing";
} else if (typeof(manifest.containerId) !== "number" || manifest.containerId <= 0 || manifest.containerId === null || !Number.isInteger(manifest.containerId)) {
copy.containerId = "Invalid";
}
if (manifest.destination === undefined) {
copy.destination = "Missing";
} else if (typeof(manifest.destination) !== "string" || manifest.destination.trim() === "") {
copy.destination = "Invalid";
}
if (manifest.weight === undefined) {
copy.weight = "Missing";
} else if (typeof(manifest.weight) !== "number" || manifest.weight <= 0 || Number.isNaN(manifest.weight)) {
copy.weight = "Invalid";
}
if (manifest.unit === undefined) {
copy.unit = "Missing";
} else if (manifest.unit !== "lb" && manifest.unit !== "kg") {
copy.unit = "Invalid";
}
if (manifest.hazmat === undefined) {
copy.hazmat = "Missing";
} else if (typeof(manifest.hazmat) !== "boolean") {
copy.hazmat = "Invalid";
}
return copy;
}
function processManifest(manifest) {
let validated = validateManifest(manifest);
console.log(validated);
//console.log(Object.keys(validated));
if (Object.keys(validated).length === 0) {
console.log(`Validation success: ${manifest.containerId}`);
let newWeight = normalizeUnits(manifest);
console.log(`Total weight: ${newWeight.weight} ${newWeight.unit}`);
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validated);
}
};
const object = {
containerId: 68,
destination: "Salinas",
weight: 101,
unit: "lb",
hazmat: true
};
const objectTwo = {};
const objectThree = {
containerId: 55,
destination: "Carmel",
weight: 400,
unit: "lb",
hazmat: false
};
processManifest(objectThree);
dhess
June 1, 2026, 5:16pm
4
besaidaurochs07:
console.log(validated);
Please remove or comment out this line in your processManifest function. It’s confusing the tests.