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 JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops The Refactor Challenge

david mchale
david mchale
1,434 Points

Math.random + 1

Why didnt he had the '+1' on the end of the Math.random() function to bring it from 0 to 1 considering the index value?

1 Answer

Hi David,

The Math.random() function used in this video isn't for an index value, it's for a RGB value, which can range from 0-255. If you added 1 to it, the range would be from 1-256, which wouldn't be usable with the rgb function.

Hope that helps!