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 Functions Arrow Functions Create Functions Using Arrow Syntax

do i really need upper? and what is it anyway?

https://w.trhou.se/1r09uqpxf0

In my code i omitted upper and just used getRandomNumber(); with nothing in the parentheses, so is that more concise?

I'm not really sure what upper does anyway is it a made up word (like can any name go inside the parentheses and also be placed within the formula?

Also is this just a persons prefered way to write functions, can normal functions (as commented out in my code) work just as well as arrow functions? What i mean is that if your team is using one way of declaring functions would it be ok to just do them that way rather than go against the flow?

4 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Upper is a parameter which is just a variable that is a placeholder for a value.

In the function, you are generating a random number between 1and 6. But if you add a parameter to a function of upper and use upper in replace of 6, you can call that function and make the function more flexible by passing in any upper random value you wish.

Rick Gleitz
Rick Gleitz
47,878 Points

I think upper simply lets you put in a number replacing the upper bound in the randomNumber constant, so you can change it when you call the function rather than going back into the code every time. I think he could have chosen anything, upper is simply descriptive of what it is. As to your other question, they do work the same, arrow functions are shorter and once you get used to them, supposedly easier to read (although i'm not used to them enough yet, but I can see it being true for me eventually). And I do think teams decide how they do things, so you'd stick with the team's way. At least until they decide to change it.

Its a difficult topic for me nearly 8 days now but if i call that function would i call upper?

I'm sure you're way past this now, but for others, take a look back at the lessons for function declarations and function expressions and listen to what he says about stuff inside the parentheses and how functions get called if you're not understanding the other replies..

Rick Gleitz
Rick Gleitz
47,878 Points

You call getRandomNumber() and pass a number in the parens to set the high number. You can put a different number in every time you call it if you want.