Why isn't this variable being defined? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why isn't this variable being defined?

I'm trying to make a simple guess the number game in javascript but my random number variable is getting an error saying it's not defined, https://code.sololearn.com/W945a2VVI4rc/#html is there a syntax error I'm missing? edit:fixed link, sorry

8th May 2017, 8:48 PM
Zac Parnell
Zac Parnell - avatar
3 Answers
+ 4
If you delete the while loop it will work just fine, or in the last if statement is the code GuessGame = false. If you place that outside that while loop it will also work. The best thing to do is probably to delete the while loop though.
8th May 2017, 9:00 PM
The Coding Sloth
The Coding Sloth - avatar
+ 3
Randomise a number when the window loads in a separate function and when they guessed the number you call that function again
9th May 2017, 7:58 AM
The Coding Sloth
The Coding Sloth - avatar
+ 1
Okay thanks, the while loop was the first thing that came to mind because I want this program to be able to loop back so people can play more than one time without rerunning the code, do you have any better solutions?
8th May 2017, 9:04 PM
Zac Parnell
Zac Parnell - avatar