Madhukar Krishna

Madhukar Krishna

  • 688
  • 1.4k
  • 292.2k

Javascript: While loop - looping forever

Mar 15 2014 2:33 PM
When I type "Yes" or "No" it alerts again and again. Please help.

<script type="text/javascript">
var y = prompt("Do you want to enter values, type 'Yes' or 'No'!");
while ((y.toUpperCase()!="YES") || (y.toUpperCase()!="NO"))
{
if (y.toUpperCase()=="YES")
{
alert(y);
}
else if (y.toUpperCase()=="NO")
{
alert(y);
}
else
{
alert("You have type \"" +y+ "\" which is no option! Please type again");
y = prompt("Do you want to enter values, type 'Yes' or 'No'!");
}
}
</script>

Answers (6)