Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Loops!
You have completed JavaScript Loops!
Preview
This video covers one way to prevent duplicating code in your program with a loop and a function.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now, I'll show you how I would solve this.
0:00
Currently, the same code to generate
a random RGB value appears three times.
0:02
So my first move might be to create
a function that returns a number from
0:07
0 to 255.
0:12
In RGB, that's the allowable range of
values for a red, green, or blue value.
0:13
I'll write an arrow function expression
that returns the randomizing code,
0:17
I'll name it randomValue.
0:22
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up