Tell us what’s happening:
If I use a single “=” in the if statement of my normalizeUnits function, step 6 fails because it alters the value of manifest.unit to “lb”. Switching to a stricter equality operand resolves this but causes step 2 to fail.
What could be the issue here?
Your code so far
const manifest = {
containerId: 68,
destination: "Salinas",
weight: 101,
unit: "lb",
hazmat: true
}
const normalMan = normalizeUnits(manifest);
function normalizeUnits(manifest) {
if (manifest.unit == "lb") {
let normalisedManifest = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.weight*0.45,
unit: "kg",
hazmat: manifest.hazmat,
}
return normalisedManifest;
}
}
const valMan = validateManifest(manifest);
function validateManifest(manifest) {
let validMan = {};
if (manifest.containerId === undefined) {
validMan.containerId = "Missing";
}
else if (manifest.containerId < 1 || typeof manifest.containerId != "number") {
validMan.containerId = "Invalid";
}
else {
validMan.containerId = manifest.containerId;
}
if (manifest.destination === undefined) {
validMan.destination = "Missing";
}
else if (typeof manifest.destination != "string") {
validMan.destination = "Invalid";
}
else {
validMan.destination = manifest.destination
}
if (manifest.weight === undefined) {
validMan.weight = "Missing";
}
else if (manifest.weight <= 0) {
validMan.weight = "Invalid";
}
else {
validMan.weight = manifest.weight;
}
if (manifest.unit === undefined) {
validMan.unit = "Missing";
}
else if (manifest.unit != "lb" && manifest.unit != "kg") {
validMan.unit = "Invalid";
}
else {
validMan.unit = manifest.unit;
}
if (manifest.hazmat === undefined) {
validMan.hazmat = "Missing";
}
else if (typeof manifest.hazmat != "boolean") {
validMan.hazmat = "Invalid";
}
else {
validMan.hazmat = manifest.hazmat;
}
return validMan;
}
let procMan = processManifest(manifest);
function processManifest(manifest) {
}
console.log(valMan);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator