Tell us what’s happening:
Hi everyone I am currently having an issue where I have the correct things being outputted when it comes to the validateManifest function but it states that I am not actually returning an object where it shows all missing or invalid properties. I am quite stuck here and any help is appreciated! ![]()
- If the input manifest object is not valid, your validateManifest function should return an object describing missing and/or invalid properties.
Your code so far
function normalizeUnits (manifest){
let newManifest = {
containerId: manifest.containerId,
destination: manifest.destination,
weight: manifest.weight,
unit: manifest.unit,
hazmat: manifest.hazmat
}
if(newManifest.unit === 'kg')
return newManifest;
newManifest.unit = "kg";
newManifest.weight = newManifest.weight * .45;
return newManifest;
}
function validateManifest(manifest){
let newManifest = {};
if(manifest.hasOwnProperty("containerId")){
if(manifest.containerId <= 0 || !Number.isInteger(manifest.containerId)){
newManifest.containerId = "Invalid";
}
}else{
newManifest.containerId = "Missing";
}
if(manifest.hasOwnProperty("destination")){
if(typeof manifest.destination !== 'string' ||
manifest.destination.trim() === ""){
newManifest.destination = "Invalid";
}
}else{
newManifest.destination = "Missing";
}
if(manifest.hasOwnProperty("weight")){
if(manifest.weight < 0 || isNaN(manifest.weight)){
newManifest.weight = "Invalid";
}
}else{
newManifest.weight = "Missing";
}
if(manifest.hasOwnProperty("unit")){
if(manifest.unit !== 'lb' && manifest.unit !== 'kg'){
newManifest.unit = "Invalid";
}
}else{
newManifest.unit = "Missing";
}
if(manifest.hasOwnProperty("hazmat")){
if(typeof manifest.hazmat !== 'boolean'){
newManifest.hazmat = "Invalid";
}
}else{
newManifest.hazmat = "Missing";
}
return newManifest;
}
function processManifest(manifest){
let validated = validateManifest(manifest);
let message = ``;
if(Object.keys(validated).length === 0){
console.log(`Validation success: ${manifest.containerId}`);
let normalized = normalizeUnits(manifest);
console.log(`Total weight: ${normalized.weight} ${normalized.unit}`);
}else{
console.log(`Validation error: ${manifest.containerId}`);
console.log(validated);
}
return message;
}
console.log(processManifest({ containerId: -88, destination: "Soledad", weight: NaN }))
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 OPR/133.0.0.0
Challenge Information:
Build a Cargo Manifest Validator - Build a Cargo Manifest Validator