Basic Data Structures: Check For The Presence of an Element With indexOf()#5

Tell us what’s happening:

Your code so far
function quickCheck(arr, elem) {
// Only change code below this line
if (arr.indexOf(elem) = -1) {
return false
}
else {return true}
// Only change code above this line
}

console.log(quickCheck([‘squash’, ‘onions’, ‘shallots’], ‘mushrooms’));


function quickCheck(arr, elem) {
// Only change code below this line
quickCheck.indexOf()
// Only change code above this line
}

console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

Challenge: Check For The Presence of an Element With indexOf()

Link to the challenge:

It’s usually helpful if you ask a question. But your problem is here:

if (arr.indexOf(elem) = -1) {

You’ve used the assignment operator - you need to check for equality.

When I fix that, the code passes.

1 Like

kevinSmith you are fantastic… I was so frustrated by this problem I did not realize i didn’t ask a question.

Thank you soon much for your assistance!!!

1 Like