When I type "Yes" or "No" it alerts again and again. Please help.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shweta LodhaPosted Mar 15, 2014, 4:42 PM
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);
break;
}
else if (y.toUpperCase()=="NO")
{
alert(y);
break;
}
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'!");
}
}
Madhukar KrishnaPosted Mar 16, 2014, 11:43 PM
I type "yes".
Then the while loop starts
it checks (y != "yes") result == false
then it checks (y !="no) result == true
Then it goes on iterating in the while loop.
Thanks guys!!
VulpesPosted Mar 16, 2014, 1:27 PM
Shweta LodhaPosted Mar 16, 2014, 5:48 AM
So you mean you want to run your while loop infinite times irrespesctive of whatever input you are giving ?
Lakshmanan Sethu SankaranarayanPosted Mar 16, 2014, 1:35 AM
Madhukar KrishnaPosted Mar 16, 2014, 1:15 AM