Build a Cargo Manifest Validator - Build a Cargo Manifest Validator

Tell us what’s happening:

test 7 is not passing though the output is accurate

Your code so far

const obj = {
  containerId: 33,
  destination: 'unknown',
  weight: 333,
  unit: 'kg',
  hazmat: true
}

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

function validateManifest(manifest) {
  const newObj = {}
  const { containerId, destination, weight, unit, hazmat } = { ...manifest }
  if ('containerId' in manifest) {
    typeof containerId == 'number' && containerId ? '' : newObj.containerId = 'Invalid';
    Number.isInteger(containerId) && containerId > 0 ? '' : newObj.containerId = 'Invalid';
  } else {
    newObj.containerId = 'Missing'
  }

  if ('destination' in manifest) {
    typeof destination == 'string' ? '' : newObj.destination = 'Invalid';
    destination.length > 0 && destination.trim().length == 0 ? newObj.destination = 'Invalid' : '';
    typeof destination == 'string' && destination.length == 0 ? newObj.destination = 'Missing' : '';
  } else {
    newObj.destination = 'Missing';
  }

  if ('weight' in manifest) {
    typeof weight == 'number' && weight ? '' : newObj.weight = 'Invalid';
    weight < 0 ? newObj.weight = 'Invalid' : '';
  } else {
    newObj.weight = 'Missing'
  }

  if ('unit' in manifest) {
    typeof unit == 'string' ? '' : newObj.unit = 'Invalid';
    unit !== 'kg' ? newObj.unit = 'Invalid' : '';
    unit.length > 0 && unit.trim().length == 0 ? newObj.unit = 'Invalid' : '';
    unit.length == 0 ? newObj.unit = 'Missing' : '';
  } else {
    newObj.unit = 'Missing'
  }

  if ('hazmat' in manifest) {
    typeof hazmat == 'boolean' ? '' : newObj.hazmat = 'Invalid';
  } else {
    newObj.hazmat = 'Missing';
  }
  return newObj
}
console.log(validateManifest(obj))


function processManifest(manifest) {
  const checkValid = validateManifest(manifest);
  if (checkValid.containerId) {
    console.log(`Validation error: ${manifest.containerId}`)
    console.log(checkValid)
  } else {
    console.log(`Validation success: ${manifest.containerId}`)
    const convert = normalizeUnits(manifest);
    console.log(`Total weight: ${convert.weight} kg`) 
  }
}
processManifest({ containerId: 55, destination: "Carmel", weight: 400, unit: "lb", hazmat: false })


hello!

if the manifest has a unit: “lb”, then it is a valid manifest. Currently your validateManifest is invalidating it.

In the future, when you require assistance with a specific challenge, please try to include a link to the challenge. It helps to make the process of providing help easier. Thank you.