0

How do I get a proper response for a user's input?

How would I go about having a page respond to a user's input? Say they input "a1". I want them to get "Dog" as a response. I tried having code read: var input=prompt() If (input==a1){ alert(dog) } But it says I haven't defined a1, which okay but simply adding a variable as a1 doesn't do anything. I cant imagine how giving a1 any value would fix anything. Any thoughts?

29th Oct 2019, 7:54 PM
Monkey Jesus
Monkey Jesus - avatar
2 Réponses
+ 2
Monkey Jesus , if you want to check if input equals to certain string => "a1", you can achieve it for example this way. Hope it helps you 🐱 https://code.sololearn.com/W9MAK3KPNBJe/?ref=app
29th Oct 2019, 8:09 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Found that I can give each answer a unique number value, which makes it work fine. Though, if there's other better ways to do this please let me know.
29th Oct 2019, 8:01 PM
Monkey Jesus
Monkey Jesus - avatar