Basic Data Structures: check for the presence of an element; Is anyone aware of bugs on this lesson as i've tried all three given solutions , they didn't work

Tell us what’s happening:
Describe your issue in detail here.
I keep getting ‘arr.indexof is not a function’ I’m completely lost!

  **Your code so far**

function quickCheck(arr, elem) {
// Only change code below this line
arr.indexof(elem) >= 0 ? true : 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/98.0.4758.80 Safari/537.36 Edg/98.0.1108.50

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

Link to the challenge:

TypeError: arr.indexof is not a function

woops…

Example:

fruits.indexOf('dates');

Do you see a very small, single character difference?

2 Likes

And it is correct. Please read up on the method here. When in doubt, check the docs.

2 Likes

Thanks for your help but including (‘elem’) with quotation still doesn’t work
assuming that was what you meant. Again thankyou though it is appreciated.

I would hope not! Converting the name of a variable into a string would make things worse!


You wrote

The example wrote

There is a singe character difference between the two.

1 Like

Thanks your correct, can’t believe i’ve missed that. Though I changed the code to (typeOf) it’s now saying undefined so I guess i’ll just ry and solve it from here thanks.

I’m not too clear on what information to glean from the link but that’s just me being very new to these things. Your suggestion was most appreciated thankyou.

I solved it with my original answer and it turned out that type…(O)…f was where i went wrong as you said. Well done and again THANKYOU!

That’s cool. I was just pointing you to where you could find the correct spelling for that method. When in doubt about a method (or a lot of JS) looking it up in the MDN docs is a good move. I do it all the time.

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