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 trialMichael Musch
1,894 PointsWhy was there no mention of when and when not to use parenthesis?
Why was there no mention as to when and why to use parenthesis in this challenge?
As a beginner it seems totally arbitrary that the parenthesis are included or omitted in the template literal including "value()" and the call to "randomValue", yet it has a very real effect on the code which hasn't been explained to us.
3 Answers
Steven Parker
231,248 PointsYou didn't mention which course or challenge you are working with, but placing parentheses after a function name is the syntax you use to invoke (or "call") the function. This concept should have been introduced in your course or one of its prerequisites.
This syntax is unrelated to the template literal, and is the same whether the function is called in a template literal token or in ordinary code.
Michael Musch
1,894 PointsThank you very much, would have been great if the video explained that!
Michael Musch
1,894 PointsI'm only able to mark your first reply, however the second reply was the most helpful. I've marked your first reply as 'best answer' anyway, hopefully anyone with the same issue just reads on further...
Michael Musch
1,894 PointsMichael Musch
1,894 PointsI clicked on the Questions tab of the video, clicked on view all discussions, then clicked ask, and it didn't automatically associate my question with the video? I thought by asking there it would put my question into the list of questions shown on that video's question tab. How unintuitive...
I appreciate your response Steven but without the context of the video my question makes no sense and as a result your answer doesn't satisfy.
This is the video in question: https://teamtreehouse.com/library/the-refactor-challenge-duplicate-code
You'll see he invokes the arrow function 'randomValue' without a parenthesis when passing it in to the function randomRGB as an argument. In previous videos functions had always been called with parenthesis (as you eluded to) but now all of a sudden they're omitted without explanation... Why?
Steven Parker
231,248 PointsSteven Parker
231,248 PointsA question is associated with a lesson when it is created using the "Get Help" button in the right sidebar of the video page.
When calling the "randomRGB" function, the argument is a function reference that will be used to get color values. It is not being invoked at that point. The color function gets invoked (3 times) inside the randomRGB function using the parameter name "value".