0

In Chrome console, I am getting this error,

Uncaught ReferenceError: operations is not defined at :1:1 (anonymous) @ VM118:1

yet this snippet runs here when I pasted it in.

What am I missing? I am trying to declare 4 functions, and capture them in a variable as an array, and then loop over that array.

function add(x, y) {
  return x + y;
}

const subtract = function(x, y) {
  return x - y;
}

function multiply(x, y) {
  return x * y;
}

const divide = function(x, y) {
  return x / y;
}

//We can store functions in an array!
const operations = [add, subtract, multiply, divide];

//Loop over all the functions in operations
for (let func of operations) {
  let result = func(30, 5); //execute func!
  console.log(result);
}
lupin4
  • 15
  • 9
  • Try to use `var` instead of `const` and `let`. Here you can find more info https://stackoverflow.com/questions/24008366/using-ecmascript-6 – Ozgur Sar Dec 08 '20 at 04:53
  • Didn't get any -- checked in chrome console – KcH Dec 08 '20 at 04:58
  • @OzgurSar That question was asked and answered in 2014. `const` and `let` have been around for a while now. Unless OP is using a very old browser, I doubt that's the issue. – Dennis Hackethal Dec 08 '20 at 05:39

0 Answers0