+ 1

How to make if else statement using prompt

I want to make a if else statement using prompt, like if someone enter a thing that i want, it will show this else show that.. Can anyone teach me how to do it?

11th Sep 2017, 11:27 PM
Blugon
Blugon - avatar
7 Answers
+ 7
var input = prompt(); if(input == "something") // do this else // do this
11th Sep 2017, 11:41 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
There are many ways to do an if/else statement. Please narrow it down to a language or specific code question?
11th Sep 2017, 11:33 PM
Samantha Jordan
Samantha Jordan - avatar
+ 1
Thanks for the help
11th Sep 2017, 11:44 PM
Blugon
Blugon - avatar
+ 1
var person = prompt("Please enter your name", "Blugon"); if (person == null || person == "") { txt = "User cancelled the prompt."; } else { txt = "Hello " + person + "! How are you today?"; } alert(txt); txt is String variable (but no declaration in JavaScript).
11th Sep 2017, 11:46 PM
Mikhael Anthony
Mikhael Anthony - avatar
+ 1
What does the (person == null || person == '") Means?
12th Sep 2017, 2:01 AM
Blugon
Blugon - avatar
0
person == null or person == ""
12th Sep 2017, 3:23 AM
Styxincewa
Styxincewa - avatar
0
|| is or operator @Blugon
12th Sep 2017, 3:24 AM
Styxincewa
Styxincewa - avatar