+ 2

(SOLVED) I need help with JavaScript functions, prompts and alerts in my code

I need help, i want this code to alert "press ok to continue" if a name or anything is typed but alert "please type your name" if the field is left blank https://code.sololearn.com/W2W7m85tm7Vc/?ref=app

21st May 2017, 1:51 PM
DeAngelo
DeAngelo - avatar
4 Answers
+ 16
function sayHello(name) { alert("Hi, "+name +", please press OK to continue"); } while (!(name=prompt("Please type your name"))) {} sayHello(name);
21st May 2017, 2:08 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 17
Loop is normally executed if returned value of arguements is true, here we want the opossite, we want the user to be re-prompted if he inputs a false value....... "!" inverts boolean value from true to false and opossite....
21st May 2017, 2:12 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
@ValentinHacker thank you a lot I love the community here, can you tell me what the exclamation mark does
21st May 2017, 2:11 PM
DeAngelo
DeAngelo - avatar
+ 2
function sayHello(name){ alert("Hi "+ name +", Please press OK to continue"); } var name = prompt("please Enter your name"); while(name === '') { alert("please type your name"); var name = prompt("please Enter your name"); } sayHello(name);
21st May 2017, 2:25 PM
ahmad mansouri
ahmad mansouri - avatar