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 🙇🏻‍♂️

3rd Apr 2021, 12:52 PM
Wai Lim
Wai Lim - avatar
9 ответов
+ 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
3rd Apr 2021, 1:10 PM
A͢J
A͢J - avatar
+ 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.
3rd Apr 2021, 1:22 PM
A͢J
A͢J - avatar
0
Wai Share code
3rd Apr 2021, 12:56 PM
A͢J
A͢J - avatar
0
Wai It's w3schools code where is yours?
3rd Apr 2021, 12:58 PM
A͢J
A͢J - avatar
0
get the input value when u click submit,not when the script just load edit:also check ur correctanswe variable name
3rd Apr 2021, 1:03 PM
durian
durian - avatar
0
That mean my code is correct if I use it on browser but not mobile?
3rd Apr 2021, 1:18 PM
Wai Lim
Wai Lim - avatar
0
Ok thank you
3rd Apr 2021, 1:26 PM
Wai Lim
Wai Lim - avatar
0
Try comparing using '===' sign
5th Apr 2021, 9:50 AM
Parth Shendge