this simple code works fine
var gotname= false;
while (gotname==false){
var username =prompt ("passanger ,what's yout name");
if (confirm("ar u " + username + "?")){
alert ("welcome "+ username);
gotname=true;
}
}
after add some validation conditions to ensure that the input not null and words only .the code didn't work as i want the massage alert confirm("ar u " + username + "?") didn't catch the username value and show instead value "false "
and this is my code
var gotname= false;
while (gotname==false){
var username =prompt ("passanger ,what's yout name");
if( (username === null) || (username =! /^[A-Za-z ]+$/.test(username)) ){alert("enter valid one without numbers ! words only")}
else
{confirm("ar u " + username + "?")}
alert ("welcome "+ username);
gotname=true;
}
and tried too
var gotname= false;
while (gotname==false){
var username =prompt ("passanger ,what's yout name");
if( username === null && username =! /^[A-Za-z ]+$/.test(username) ){alert("enter valid one")}
else if (confirm("ar u " + username + "?")){
alert ("welcome "+ username);
gotname=true;
}
}
(username =! /^[A-Za-z ]+$/.test(username)). The operator is!=, but that doesn't even seem right.