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 trialTow Boon Ng
14,507 PointsrandomNumber is used twice in this video. Will this following scenario happen??
if (randomNumber === guess) , produce a number. e.g. 5 prompt , User guess prompt another number, e.g. 6
it is wrong, else statement will be called. and it also generates a randomNumber ? is this the same randomNumber, 5? or a different randomNumber.
i.e. IF statement, randomNumber = 4 user guess = 3. ELSE statement generates a different random number. randomNumber=3 coincidentally "Sorry the number you guess is 3"
1 Answer
jag
18,266 PointsAs long as the function that generates the random number isn't included in the loop then only one variable will be defined no matter how many tries.
If the random number is included within the loop then each time it will generate a new number and it can even generate the same number as it previous had.
Tow Boon Ng
14,507 PointsTow Boon Ng
14,507 PointsHi @jag, do you mean the same loop basis on below comment in my code??
jag
18,266 Pointsjag
18,266 PointsNot sure how you would be getting a different number. I looped it through multiple guess and randomNumber doesn't change within the loop. The only way it would change is if you had a function outside that created a new loop and you called that function every time.