Tell us what’s happening:
getting confused why its showing issue in step 15 first it was showing for step 7
Your code so far
const normalizeUnits = (manifest) => {
let newManifest = { ...manifest };
if (newManifest.unit.toLowerCase() === "lb") {
newManifest.unit = "kg";
newManifest.weight = newManifest.weight * 0.45;
}
return newManifest;
}
const validateManifest = (manifest) => {
let errors = {};
if (manifest.containerId === undefined) {
errors.containerId = "Missing";
} else if (typeof manifest.containerId !== "number" || manifest.containerId <= 0 || !Number.isInteger(manifest.containerId)) {
errors.containerId = "Invalid";
}
if (manifest.destination === undefined) {
errors.destination = "Missing";
} else if (typeof manifest.destination !== "string" || manifest.destination.trim() === "") {
errors.destination = "Invalid";
}
if (manifest.weight === undefined) {
errors.weight = "Missing";
} else if (typeof manifest.weight !== "number" || manifest.weight <= 0 || Number.isNaN(manifest.weight)) {
errors.weight = "Invalid";
}
if (manifest.unit === undefined) {
errors.unit = "Missing";
} else if (typeof manifest.unit !== "string" || !["kg", "lb"].includes(manifest.unit.toLowerCase())) {
errors.unit = "Invalid";
}
if (manifest.hazmat === undefined) {
errors.hazmat = "Missing";
} else if (typeof manifest.hazmat !== "boolean") {
errors.hazmat = "Invalid";
}
return errors;
}
const processManifest = (manifest) => {
let validationResult = validateManifest(manifest);
if (Object.keys(validationResult).length === 0) {
let normalizedManifest = normalizeUnits(manifest);
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${normalizedManifest.weight} kg`);
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validationResult);
}
};
console.log(processManifest({ containerId: -88, destination: "Soledad", weight: NaN, unit: "pound", hazmat: "1" }));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator