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 trialStephen Chamroeun
7,095 PointsInstead of 10 dots, I'm getting plenty more.
This is my current code in the snapshot I took. I took the code that generated the colors and set them inside a function called randomColorGenerator(). Then I went ahead and created a For Loop that would technically write the function to the page 10 times. Instead of the For Loop writing the called function 10 times, it writes it quite a bit more then that. In the mean time while I wait for an answer, I'll continue to experiment with the code.
**Edit - I was able to generate just 10 dots to the page. I declared the variables within the functions instead and deleted them outside the functions. I'm still curious as to how leaving the variables declared outside the function I created would create more than 10 variables?
1 Answer
Armin Kadic
16,242 PointsThere are 2 reasons why you get more than 10 dots. One is on line 12, after the html you don't need a +=, that keeps adding up to the variable. All you need is an = sign. This will fix the main problem but there is one left, you will keep getting 11 dots because on line 16 you wrote i <= 10, since i is 0, it will count 11 because you but the = sign. If you just put a < sign it will count 10. This will make your code work but you can make it shorter and more DRY. Why not make a function that generates one random number instead of giving it to every color individually. Later you can call the function in the rgbColor variable multiple times instead of writing red green blue.
I hope this helps!