0

Why am i getting " input22 is undefined" ?

Basically what I am trying to do is when the user types in the no. the no.s get stored in variable and if they match the random no. he will win

31st May 2017, 5:35 PM
_Retr0/-
_Retr0/- - avatar
8 odpowiedzi
+ 3
The error is caused because there is no variable input22. There var input22 that was in the window.onload function is a local variable. Fix: var input22; window.onload = function(){ input22 = .... } Then you can use it in a different function like you intended. Note* even after that change it looks like what you're setting input22 to is still giving null. (You won't receive an error but there is no right ans). Unless the numbers you had under that 'calculator thing' weren't the right answer anyway.
31st May 2017, 5:46 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
We would need to see the code. There could be many reasons why "input 22 is undefined". Maybe you forgot to write var, or initialize it. Idk.
31st May 2017, 5:38 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
declare input22 var as global: var input22 window.onload = function () { input22 = document.getElementById("input_num").innerHTML; }
31st May 2017, 5:47 PM
Calviղ
Calviղ - avatar
0
oops sorry I forgot to post the code
31st May 2017, 5:39 PM
_Retr0/-
_Retr0/- - avatar
0
lol man silly me
31st May 2017, 5:39 PM
_Retr0/-
_Retr0/- - avatar
0
@Rrestoring faith they r indeed the right answer (I added them to test it)
31st May 2017, 6:58 PM
_Retr0/-
_Retr0/- - avatar
0
well @Rrestoring faith and @Calvin that problem is solved but now I can't get the answer to be right
31st May 2017, 7:05 PM
_Retr0/-
_Retr0/- - avatar