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 trialitaliandadx2
3,566 PointsProblem with the value parameter
Wouldn't the value past into the function be the same for each rgb number...? Meaning when you call the function and pass it a value of say 10... wouldn't the color returned be rgb(10, 10, 10)...? I guess you still get a random color for each circle but each color would have the same value for for r, g and b... rgb(10, 10, 10), rgb(127, 127, 127), etc...
3 Answers
Peter Vann
36,427 PointsHi!
If you pay close attention to the video right around 5:00, you will notice that the value is actually the randomValue function being passed in.
The give-away being this line of code:
const color = `rgb( ${value()}, ${value()}, ${value()} )`;
Which tells you that value() has to be an executable function (randomValue, specifically, which will randomly generate a fresh, distinct number each time it is called - in this case, three times right in a row).
Does that make sense?
I hope that helps.
Stay safe and happy coding!
Yazeed Hani
5,002 PointsSo you're not actually passing the randomValue function into the randomRGB function in the for loop. You are just passing in the word "randomValue" as an argument to the randomRGB function. The parameter "value" in the function defintion of randomRGB will store the word "randomValue" and pass it into the ${value()} placeholders.
So, technically, ${value()} is literally ${randomValue()}.
daniel barreto
4,145 PointsWhen you pass " randomValue" to "randomRGB" you are only passing the variable "randomValue" which
happens to be a function. " randomValue" exists inside "randomRGB" as a term called "value".
when ${ value() } is ran it is invoking the "randomValue()" function. the parenthesis make the function perform
its operation.
italiandadx2
3,566 Pointsitaliandadx2
3,566 PointsThank you! Took me a minute to get what you were saying... I didn't realize that when you pass a function as an argument that the function would be called independently each time it's referenced... Thank you again!!!