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
8 Réponses
+ 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.
+ 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.
+ 1
declare input22 var as global:
var input22
window.onload = function () {
input22 = document.getElementById("input_num").innerHTML;
}
0
oops sorry I forgot to post the code
0
lol man silly me
0
@Rrestoring faith they r indeed the right answer (I added them to test it)
0
well @Rrestoring faith and @Calvin that problem is solved but now I can't get the answer to be right