Failed to solve: Check For The Presence of an Element With indexOf()

Tell us what’s happening:

Getting stuck with this code i tried to make it work but, it just doesn’t. Also i failed to understand what i need to add excatly here.
Your code so far

function quickCheck(arr, elem) {
// Only change code below this line

// 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/83.0.4103.61 Safari/537.36.

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

Link to the challenge:

You should use the Array prototype method indexOf (as the instructions suggest), not includes.

indexOf takes a single argument, the value to search for in the array.

1 Like

Hello @KittyKora,

The challenge asks you to create a function that checks if a certain element exist inside an array using .indexOf();. The .indexOf(); will an array what position an element is, here’s an example:

let arr = [1, 2, 3, 4, 5];
let check = arr.indexOf(4);
console.log(check)//this will return 3
let check2 = arr.indexOf(6);
console.log(check2)//this will return -1 because it doesn't exist

So from this, you can create a function that checks if an element exist in an array, if not return false, if it does return true.

1 Like

You have a typo there, should be arr.indexOf(includes("")) but you are also passing an elem parameter. You need to return that value as well. Maybe what you need is something like arr.indexOf(includes(elem)) ?

1 Like