Problem with processManifest() tests 21, 25, and 26
I have completed the normalizeUnits() and validateManifest() functions, and all their tests are passing. However, tests 21, 25, and 26 for processManifest() are failing.
My function follows the requirements: it validates the manifest, logs Validation success: ${containerId} and the normalized weight for valid manifests, and logs Validation error: ${containerId} followed by the validation object for invalid manifests.
I have also tried logging the result directly with console.log(validateManifest(manifest)), but the tests still fail.
Could someone help me identify what I might be missing?
const manifest = {
containerId: 1,
destination: "Monterrey, California",
weight: 831,
unit: "lb",
hazmat: true
};
const manifest2 = { containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false };
const normalizeUnits = (manifest) => {
const copyManifest = {...manifest};
if (copyManifest.unit === "lb") {
copyManifest.weight = copyManifest.weight * 0.45;
}
copyManifest.unit = "kg";
return copyManifest;
};
const validateManifest = (manifest) => {
const copyManifest = {};
const requeridas = ["containerId", "destination", "weight", "unit", "hazmat"];
for(const field of requeridas){
if (!(field in manifest)){
copyManifest[field] = "Missing";
continue;
}
switch(field) {
case "containerId":
if (typeof manifest[field] !== "number" ||
!Number.isInteger(manifest[field]) ||
manifest[field] <= 0) {
copyManifest[field] = "Invalid";
}
break;
case "destination":
if (typeof manifest[field] !== "string" ||
manifest[field].trim() === "") {
copyManifest[field] = "Invalid";
}
break;
case "weight":
if (typeof manifest[field] !== "number" ||
manifest[field] <= 0 ||
Number.isNaN(manifest.weight)) {
copyManifest[field] = "Invalid";
}
break;
case "unit":
if (!["kg", "lb"].includes(manifest[field])) {
copyManifest[field] = "Invalid";
}
break;
case "hazmat":
if (typeof manifest[field] !== "boolean") {
copyManifest[field] = "Invalid";
}
break;
}
}
return copyManifest;
}
const processManifest = (manifest) => {
const validation = validateManifest(manifest);
if (Object.keys(validation).length === 0) {
console.log(`Validation success: ${manifest.containerId}`);
const normalized = normalizeUnits(manifest);
console.log(`Total weight: ${normalized.weight} kg`);
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validateManifest(manifest));
}
};
InformaciĂłn de tu navegador:
El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
InformaciĂłn del desafĂo:
Construye un validador de manifiestos de carga - Crear un validador de manifiestos de carga
Enlace de GitHub: i18n-curriculum/curriculum/challenges/espanol/blocks/lab-cargo-manifest-validator/69a56b5069ca99f7317e6e19.md at main · freeCodeCamp/i18n-curriculum · GitHub