0

While loop for 2 different conditions

I am trying to do 2 different while loop, as below: var x=["andy","sam"]; var y=prompt("Who are you?");{ while(y!=x.find(n=>n==y)){ alert("You are not authorized!"); var y=prompt("Who are you?"); } how about if i want to do the while loop also occur if the input is equal to null? if i do multiple while, it will loop over and over again. can anyone help me? Thank you.

16th Oct 2016, 9:32 AM
Tripley Yong
Tripley Yong - avatar
1 Antwort
+ 2
Use || (logical or operator) for that. var x=["andy","sam"]; var y=prompt("Who are you?"); while(y==""||y!=x.find(n=>n==y)){ alert("You are not authorized!"); y=prompt("Who are you?"); } alert("Welcome!"); Other boolean operators: && (and), ! (not).
16th Oct 2016, 9:55 AM
Zen
Zen - avatar