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!

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 Loops, Arrays and Objects Simplify Repetitive Tasks with Loops A Closer Look at Loop Conditions

Mari Selvan
Mari Selvan
2,438 Points

why we should not use the variable "randomnumber" instead of getRandomNumber(upper); in place of guess=______?

because both are same....

can you post some code as to make it easier for us to see visually what your questions is. Are you saying that the variable "randomNumber" is the same as the function getRandomNumber, and why use the variable in the condition statement in the video, rather than the function?

3 Answers

Because if you replace getRandomNumber(upper) for randomNumber you don't actually generate a random guess, you tell your guess already what the number is, which results in your loop will run just once while it's empty, you'll always get computer needed 1 attempt to get it right! Hope I'm not mistaking.......

Elena Paraschiv
Elena Paraschiv
9,938 Points

That makes sense. Thanks. Was just about to ask the same question.

Its mostly used for style and debugging purposes more so than anything else. and it looks cleaner I personally think.

here is a great article on named function expressions.