The code i wrote to solve it doesn;t work: Check For The Presence of an Element With indexOf()

Tell us what’s happening:
If I check for solutions here I get the immediate solution.
Could use some help with this one.

Your code so far


function quickCheck(arr, elem) {
// Only change code below this line
if quickCheck.indexOf(arr == [0-9]) { //use the indexoff just like in the example then it compares the array to 0 trough 9. since dates was the only number being postive
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/83.0.4103.61 Safari/537.36.

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

Link to the challenge:

that’s not like in the example

quickCheck is the function name, you can’t use the indexOf method on it, you need to use it on the array

1 Like

Well that does make scense actually. Did’t saw it was a let and not a function.
Yes I changed the spelling

if arr.indexOf(elem == [0-9]) { 
  return true;
} else {
  return false;
}
};

That is not how an if statement looks, nor how indexOf works.

if (true) {
  console.log('always blue, always blue, always blue');
}

if true {
  // SyntaxError: Unexpected token
}

// also be mindful that index 0 is a falsy value, so you can't just use the index
if ([1, 2, 3].indexOf(1)) {
  console.log('Index 0 is a falsy value so this never runs');
}

if ([1, 2, 3].indexOf(1) >= 0) {
  console.log('True index 0 is greater than or equal to 0');
}