Tell us what’s happening:
Steps 21, 25, 26 will not validate, cannot determine where the code is not logging correctly. I have modified my code multiple times while checking the validation in case it was a small error somewhere, though it seems to point to the processManifest function. I even went as far as to compare my solution to the GitHub solution, and update my functions to resemble it to make sure I didn’t miss anything. I am stumped at this point. I assume that I am missing something simple, but can’t see it. Any help would be appreciated!
Your code so far
const weightConversionRate = 0.45
const normalizeUnits = function(manifest) {
const newManifest = {...manifest};
if (newManifest.unit === "lb") {
newManifest.unit = "kg";
newManifest.weight *= weightConversionRate;
}
return newManifest;
}
const validateManifest = function(manifest) {
const testingManifest = {};
if (manifest.containerId === undefined) {
testingManifest.containerId = "Missing";
}
else if (typeof(manifest.containerId) !== "number" || manifest.containerId <= 0 || !Number.isInteger(manifest.containerId)) {
testingManifest.containerId = "Invalid";
}
if (manifest.destination === undefined) {
testingManifest.destination = "Missing";
}
else if (typeof(manifest.destination) !== "string" || manifest.destination.trim() === "") {
testingManifest.destination = "Invalid";
}
if (manifest.weight === undefined) {
testingManifest.weight = "Missing";
}
else if (typeof(manifest.weight) !== "number" || manifest.weight <= 0 || Number.isNaN(manifest.weight)) {
testingManifest.weight = "Invalid";
}
if (manifest.unit === undefined) {
testingManifest.unit = "Missing";
}
else if (manifest.unit !== "lb" && manifest.unit !== "kg") {
testingManifest.unit = "Invalid";
}
if (manifest.hazmat === undefined) {
testingManifest.hazmat = "Missing";
}
else if (typeof(manifest.hazmat) !== "boolean") {
testingManifest.hazmat = "Invalid";
}
return testingManifest;
}
const processManifest = function(manifest) {
const validatedManifest = validateManifest(manifest);
if (Object.keys(validatedManifest).length > 0) {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validatedManifest);
}
else {
const normalizedManifest = normalizeUnits(manifest);
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${normalizedManifest.weight} kg`);
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator