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
Daniel Morel
2,957 PointsConfused
My confusion lies in why did he create a var in the global side named var randomNumber = getRandomNumber(upper);
Then he creates a function named function getRandomNumber( upper).
and then uses it on the loop . I understand why you need to create the var guess; but then he uses it with the getRandomNumber. .
So my two questions are as follows.
- Why did he create a variable with the same name as the function.
- on the
while () {}section thegetRandomNumberis he using thevaror the Function.
1 Answer
Michael Hulet
47,913 PointsThis question apparently failed to tie to a video, so it's hard to know exactly what video you're referring to, but I can probably still answer at least part of your question. The variable randomNumber has a distinct name from the function getRandomNumber. They are not the same. In the code you posted, randomNumber contains the result of calling getRandomNumber. If the teacher used getRandomNumber inside the while loop you're referring to, they're using the function getRandomNumber, and not the variable randomNumber
Daniel Morel
2,957 PointsDaniel Morel
2,957 PointsHere's the link https://teamtreehouse.com/library/a-closer-look-at-loop-conditions
Michael Hulet
47,913 PointsMichael Hulet
47,913 PointsFYI: There's still no link here
Daniel Morel
2,957 PointsDaniel Morel
2,957 PointsHeres the link https://teamtreehouse.com/library/a-closer-look-at-loop-conditions