I cant seems to get this to work.
<script language="JavaScript">
var name = null;
do
{
var name = prompt("Please enter your full name","");
}
while(name != null);
</script>
I cant seems to get this to work.
<script language="JavaScript">
var name = null;
do
{
var name = prompt("Please enter your full name","");
}
while(name != null);
</script>
When you enter a blank string and press OK, it returns a empty string not null, null
is returned only when you press cancel.
You can test for truthyness of the returned value
var name = null;
do {
name = prompt("Please enter your full name");
console.log(name)
}
while (!name);
console.log('done', name)
I would use a boolean value:
Also you were re-declaring the
name
var again on within thedo
loop, remove thevar
in the loop.