function quickCheck(arr, elem) {
// Only change code below this line
if(arr.indexOf(elem)>=0){
return true
}else{
return false
}
// Only change code above this line
}
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
I don’t understand what this means >=0? why is it needed and why does it reveal truth without it? but it should be false
>= means greater than or equal to. 0 is of course zero. You’ve already discussed how indexOf works, so you should know that it returns the numeric index of the element or -1 if it doesn’t exist.
So, put that all together and you see that line of code is testing if indexOf returns a number greater than or equal to 0 (if the element exists) and returns true if so, false otherwise.
I’m assuming you want to know why the comparison to 0 is needed vs just doing if (arr.indexOf(elem)){. As you already know, when the element is not found, indexOf returns a result of -1 which is a truthy value and thus will follow the if branch, which is not what is wanted.