How do I connect the if statement and the else to the prompt so I if a user types something and what he types will activate if | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

How do I connect the if statement and the else to the prompt so I if a user types something and what he types will activate if

Or else

14th Dec 2021, 12:01 AM
branvie sumanting
branvie sumanting - avatar
3 Respuestas
+ 1
Just set a variable for the prompt. For example, you want to challenge the user to answer "1+2" and if the user writes "3" in the prompt, it will say "Correct" and if not, it will say "wrong". var sum = prompt ("What is the sum of 1+2?"); if (sum == "3"){ alert("Correct"); }else { alert("Wrong"); } I hope that answers your question.
14th Dec 2021, 4:05 AM
Rean Glenn Roquero
Rean Glenn Roquero - avatar
+ 1
Indeed answered it
14th Dec 2021, 5:44 AM
branvie sumanting
branvie sumanting - avatar
0
But what about the code "confirm"
14th Dec 2021, 6:07 AM
branvie sumanting
branvie sumanting - avatar