Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing the Practice

Why are indexes repeating when value in array repeats?

When the random number as a value in the array repeats, so does the index. Here is a visual: https://imgur.com/a/ME4ItgE

1 Answer

The indexOf() method returns the position of the first occurrence of a specified value in a string.

myRandomList.indexOf(myRandomList[i])

looks for the first occurrence of value myRandomList[i]

It would be easier to just use i instead.

How didn't I realized that!!!!! that did it!!!! Thank you!