Tell us what’s happening:
застряла на тесте номер 15, не понимаю, как его сделать и что не так
Your code so far
function normalizeUnits(manifest){
const copy = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.unit === "kg" ? manifest.weight : manifest.weight * 0.45,
unit: "kg",
hazmat: manifest.hazmat
}
return copy;
}
console.log(normalizeUnits({ containerId: 68, destination: "Salinas", weight: 101, unit: "lb", hazmat: true }));
function validateManifest(manifest){
const validatedManifest = {};
if (manifest.containerId === undefined) {
validatedManifest.containerId = "Missing";
} else if (typeof(manifest.containerId) !== "number" || !Number.isInteger(manifest.containerId) || manifest.containerId <= 0) {
validatedManifest.containerId = "Invalid";
}
if (manifest.destination === undefined) {
validatedManifest.destination = "Missing";
} else if (typeof(manifest.destination) !== "string" || (manifest.destination).trim() === "") {
validatedManifest.destination = "Invalid";
}
if (manifest.weight === undefined) {
validatedManifest.weight = "Missing";
} else if (typeof(manifest.weight) !== "number" || manifest.weight < 0 || Number.isNaN(manifest.weight)) {
validatedManifest.weight = "Invalid";
}
if (manifest.unit === undefined) {
validatedManifest.unit = "Missing";
} else if (manifest.unit !== "lb" && manifest.unit !== "kg") {
validatedManifest.unit = "Invalid";
}
if (manifest.hazmat === undefined) {
validatedManifest.hazmat = "Missing";
} else if (typeof(manifest.hazmat) !== "boolean") {
validatedManifest.hazmat = "Invalid";
}
return validatedManifest;
}
function processManifest(manifest){
const validationResult = validateManifest(manifest);
if (Object.keys(validationResult).length === 0) {
console.log(`Validation success: ${manifest.containerId}`);
const normalizedManifest = normalizeUnits(manifest);
console.log(`Total weight: ${normalizedManifest.weight} kg`);
} else {
console.log(`Validation error: ${manifest.containerId}`);
console.log(validateManifest(manifest));
}
};
processManifest({ containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false });
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator