1

I'm attempting to create a new array var class = [] based off an array of arrays and comparing the indices within those. when i run the test it's telling me that the = in the var class = [] is a syntax error. Not sure exactly what i'm doing wrong.

function list(names) {
  var class = [];
  var array = names.map(function(obj) {
    for (var i = 0; i < obj.length; i++) {
      if (obj[0] > 55 && obj[1] > 7) {
        class.push("Name1")
      } else {
        class.push("Name2")
      }
      return class;
    }
  });
};
console.log(
list([
[18, 20],
[45, 2],
[61, 12],
[37, 6],
[21, 21],
[78, 9]
])
)
mplungjan
  • 169,008
  • 28
  • 173
  • 236
peters313
  • 59
  • 5
  • 1
    Dont use class...it is javascript reserved name...use something else for variable name – Sagi Nov 17 '17 at 15:45

2 Answers2

2

class is a reserved word in javascript. Change it to something else, you should be good.

jmargolisvt
  • 5,722
  • 4
  • 29
  • 46
1

you can't use reserved words for variables..class is reserved here is the link for reserved words https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar

sumeet kumar
  • 2,628
  • 1
  • 16
  • 24