Build a Cargo Manifest Validator - Test 15

I am just stock on test 15 can smn help me point out where I go it all wrong

// Copy Object

function copyObject(manifest, obj)
{
// Adding properties to new object
obj.containerId = manifest.containerId;
obj.destination = manifest.destination;
obj.weight = manifest.weight;
obj.unit = manifest.unit;
obj.hazmat = manifest.hazmat;
}

// Normalize Units
function normalizeUnits(manifest)
{
// Create a new object
let obj = new Object();

// Copying Object
copyObject(manifest, obj);

// Conversion from 'lb' to 'kg'
if(obj.unit == "lb")
{
obj.unit = "kg";
obj.weight = obj.weight \* 0.45;
}

return obj;
}

// Validate Manifest
function validateManifest(manifest)

let obj = new Object(manifest);

let check_obj = new Object();

if(obj.hasOwnProperty("containerId") == false)
{
check_obj.containerId = "Missing";
}
else if(!Number.isInteger(obj.containerId) || obj.containerId <= 0 || obj.containerId == null)
{
check_obj.containerId = "Invalid";
}

if(obj.hasOwnProperty("destination") == false)
{
check_obj.destination = "Missing";
}
else if(obj.destination == '' || obj.destination == '  ' || typeof(obj.destination) == "number" || obj.destination == null)
{
check_obj.destination = "Invalid";
}

if(obj.hasOwnProperty("weight") == false)
{
check_obj.weight = "Missing";
}
else if(obj.weight <= 0 || obj.weight == null || isNaN(obj.weight))
{
check_obj.weight = "Invalid";
}

if(obj.hasOwnProperty("unit") == false)
{
check_obj.unit = "Missing";
}
else if(obj.unit != 'lb' && obj.unit != 'kg')
{
check_obj.unit = "Invalid";
}

if(obj.hasOwnProperty("hazmat") == false)
{
check_obj.hazmat = "Missing";
}
else if(obj.hazmat != true && obj.hazmat != false)
{
check_obj.hazmat = "Invalid";
}

return check_obj;
}

function processManifest(manifest)
{
let newManifest = validateManifest(manifest) ;

if (!Object.hasOwn(manifest, "containerId") || !Object.hasOwn(manifest, "destination") || !Object.hasOwn(manifest, "weight") || !Object.hasOwn(manifest, "unit") || !Object.hasOwn(manifest, "hazmat"))
{
console.log(`Validation error: ${manifest.containerId}`);
console.log(newManifest);
}
else
{
console.log(`Validation success: ${manifest.containerId}`);
newManifest = normalizeUnits(manifest);
console.log(`Total weight: ${newManifest.weight} kg`);
}
}

const m_obj = {
containerId: 1,
destination: "Monterey, California, USA",
weight: 831,
unit: "lb",
hazmat: false
}

processManifest(m_obj);

Welcome to the forum @isholausaamah!

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read and test.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').


In the future, when you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

Happy coding!

I’m seeing this syntax error in the console:

SyntaxError: unknown: Unexpected token, expected "{" (33:0)

  31 | function validateManifest(manifest) 
  32 |
> 33 | let obj = new Object(manifest);
     | ^
  34 |
  35 | let check_obj = new Object();
  36 |

You’ll need to fix that before testing further.

Try testing your code like this:

console.log(validateManifest({containerId:NaN, destination:"             ",weight: -1, unit: "pound", hazmat: 0 }))
processManifest({containerId:NaN, destination:"             ",weight: -1, unit: "pound", hazmat: 0 });