We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Return Objects

As we talked about earlier, in JavaScript, you can only return a single value from a function. So, when you want to return multiple values, you just return an object that contains those values.

function doAllTheMath(x, y) {
  const sum = x + y;
  const difference = x - y;
  const product = x * y;
  const quotient = x / y;
  return {
    sum,
    difference,
    product,
    quotient,
  };
}

const results = doAllTheMath(10, 5);
console.log(results.sum);
// 15
console.log(results.difference);
// 5
console.log(results.product);
// 50
console.log(results.quotient);
// 2

Assignment

Fix the bug with the calculateCampaignMetrics so that it returns all the defined metrics correctly.