Build a Cargo Manifest Validator lab in JavaScript

I’ve been stuck on this one for a while. It passes the tests, but says I have a syntax error on line 47.

function normalizeUnits(manifest) {
	const newManifest = {...manifest};
	if (manifest.unit == "lb") {
		newManifest.unit = "kg";
		newManifest.weight  = manifest.weight * 0.45;
	}
return newManifest; 
}

function validateManifest(manifest) {
let newManifest= {};
let invalid = false;
	if (!Object.hasOwn(manifest, "containerId")) {
			invalid = true;
			newManifest.containerId = "invalid";
}
}
	if(Object.hasOwn(manifest, "destination")) {
		invalid = true;
		newManifest.destination = "Missing";
} else {
	if (Number.isInteger(manifest.destination) || manifest.destination.trim()==="") {
			invalid = true;
			newManifest.destination = "Invalid";
}
}
if (!Object.hasOwn(manifest, "unit")) {
		invalid = true;
		newManifest.unit = "Missing";
} else { 	
		if (typeof manifest.unit !== "string" || !["kg", "lb"].includes(manifest.unit.trim().toLowerCase())) 
		// if ((manifest.unit.trim().toLowerCase() !== "lb" && manifest.unit.trim().toLowerCase()!=="kg"))
{
		invalid = true;
		manifest.unit = "Invalid";
}
}
if (Object.hasOwn(manifest, "hazmat")) {
	 invalid = true;
		newManifest.hazmat = "Missing";
} else {
	if(typeof manifest.hazmat !== "boolean") {
		invalid = true;
		newManifest.hazmat = "Invalid";
}

if (invalid != true) {
return {...newManifest};
} else {
			return {};
}
}

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`);
}
}

console.log(validateManifest({containerId: 55, destination: "Carmel", weight: .00, unit: "lb", hazmat: false});

https://www.freecodecamp.org/learn/javascript-v9/lab-cargo-manifest-validator/lab-cargo-manifest-validator

Hi @cassandraleeper4,

Did you mean to say it doesn’t pass any of the tests?

You need to fix the syntax error:


SyntaxError: unknown: 'return' outside of function. (48:0)

  46 |
  47 | if (invalid != true) {
> 48 | return {...newManifest};
     | ^
  49 | } else {
  50 | 			return {};
  51 | }

Read what it’s telling you. Look at the line number it’s pointing to.

Happy coding!

don’t you need too make two if for container id one condition when is missing the other when it is valid