Basic Data Structures - Check For The Presence of an Element With indexOf()

Tell us what’s happening:
Describe your issue in detail here.

I need to understand why I am not progressing past this stage
function quickCheck(arr, elem) {
  // Only change code below this line
  if (elem >= 0) {
    arr.indexOf(elem);
    return true
  } else {
    return false
  }
  // Only change code above this line
}

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/112.0.0.0 Safari/537.36

Challenge: Basic Data Structures - Check For The Presence of an Element With indexOf()

Link to the challenge:

You are not progressing because your code is not correct.

Modify the function using indexOf() so that it returns true if the passed element exists on the array, and false if it does not.

Your if condition doesn’t do this.

Hmmm :thinking: does this work

if (arr.indexOf(elem) >= 0){ 
......

What’s the full code?

if (arr.indexOf(elem) >= 0){ 
 return true
} else {
 return false
}

You need the function too. Otherwise the tests can’t run your code.

yes I will add the function to it. I just was not sure about it .

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.