+ 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
4 odpowiedzi
+ 16
function sayHello(name) {
alert("Hi, "+name +", please press OK to continue");
}
while (!(name=prompt("Please type your name"))) {}
sayHello(name);
+ 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....
+ 2
@ValentinHacker thank you a lot I love the community here, can you tell me what the exclamation mark does
+ 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);