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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Shweta LodhaRank #31 · 39.8K reputationPosted Mar 15, 2014, 12:42 PM EDT
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 KrishnaRank #1,382 · 1.2K reputationPosted Mar 15, 2014, 9:15 PM EDT
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Mar 15, 2014, 9:35 PM EDT
Shweta LodhaRank #31 · 39.8K reputationPosted Mar 16, 2014, 1:48 AM EDT
So you mean you want to run your while loop infinite times irrespesctive of whatever input you are giving ?
VulpesRank #55 · 29.2K reputationPosted Mar 16, 2014, 9:27 AM EDT
Madhukar KrishnaRank #1,382 · 1.2K reputationPosted Mar 16, 2014, 7:43 PM EDT
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!!