Check For The Presence of an Element With indexOf() mine

Tell us what’s happening:

i need an explanation

Your code so far


function quickCheck(arr, elem) {
  // change code below this line
if (arr.indexOf(elem)>0){// why does d arr has to be greater than zero
  return true;
} else{
  return false;
}
  // change code above this line
}

// change code here to test different cases:
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/check-for-the-presence-of-an-element-with-indexof

Calling indexOf method to an array looks at every element in its array from the beginning with a given parameter (elem). Then it compares each value to see if it’s greater than 0 if then true or else false.

Because indexOf returns -1 if the element is not found, a positive number returned means that the element was found (at that positive number as the index)

quickCheck(['squash', 'onions', 'shallots'], 'squash');

Be careful, this return false even if it should return true
Remember that the item at first position is at index 0