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
arr.indexOf(includes("");
// 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()
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.
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)) ?