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

Confused

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.

  1. Why did he create a variable with the same name as the function.
  2. on the while () {} section the getRandomNumber is he using the var or the Function.

1 Answer

This 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

FYI: There's still no link here