0
Question on basic JavaScript
First, sorry for my poor English🙇🏻♂️ I learnt the basic JavaScript recently, yesterday, I want to make a website with a simple question that user can input their answer and the JS will check whether the answer is correct or not. I use the if statement to check the answer when the user click the button. However, even the answer is correct, the if statement don’t run but the else statement run. What is going wrong??? Thank you very much 🙇🏻♂️ The code is in the comment section 🙇🏻♂️
9 Respuestas
+ 2
Wai
That link will only work on browser but not on mobile because defined variable is not loading and showing undefined. To check just alert correctAnswer.
To work only mobile you need to load JS code inside onload function or define variable inside function.
Here is your solution
https://code.sololearn.com/W2YjjFhb8wyr/?ref=app
+ 1
Wai
No you still need to load your JS code before loading contents.
w3schools is doing internally so their code will run on browser. But this is weird problem why not that link is working on mobile.
0
Wai Share code
0
Wai
It's w3schools code where is yours?
0
get the input value when u click submit,not when the script just load
edit:also check ur correctanswe variable name
0
That mean my code is correct if I use it on browser but not mobile?
0
Ok thank you
0
Try comparing using '===' sign