0

What is wrong with this function()?

I tried to write a simple guessing game to practice the 'if else' conditional statements: https://code.sololearn.com/W8u1VoX92RR6/#html I can't figure out why the function submit() only seems to increment the variable 'score' the first time (score++;). And it doesn't increment the variable 'answer' (answer++;) at all. EDIT: the code works now!

24th Sep 2018, 1:56 PM
Tyler M
Tyler M - avatar
2 odpowiedzi
+ 5
You should globally declare your variables, (AKA: on top of script and not inside function because the get redeclared and reseted) [PS: Try adding a little randomness in it ;) ]
24th Sep 2018, 2:30 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
Yes! it works! thanks Valen H, now I will try and make the number random. I just learned how to do that
24th Sep 2018, 6:25 PM
Tyler M
Tyler M - avatar