var login = prompt('Введите логин !'); if (login == 'Admin' || 'User'){ var password = prompt('Введите пароль !'); if (password == '12345'){ alert("Добро пожаловать"); } else if (password == null){ alert("Вы уже уходите?"); } else{ alert("Go away"); } } else{ alert("Who are you?"); } 

Why in the login field when I enter any digits and letters, it goes to the password entry field and does not display "Go away." : If the login is "Admin" or "User", then it displays a field for entering a password. If something else then "Go away"

  • 2
    When questions are given the correct answer, it should be taken by clicking on the check mark to the left of it. If I am not mistaken, this can be done 15 minutes after the question. - Qwertiy
  • The answer has already been given, it is only necessary to clarify that the condition login == 'Admin' || 'User' login == 'Admin' || 'User' equivalent to the condition (login == 'Admin') || 'User' (login == 'Admin') || 'User' , which is equivalent to (login == 'Admin') || true (login == 'Admin') || true , which is equivalent to (true || false) || true (true || false) || true , which is equivalent to true . - Yaant

1 answer 1

Instead

 if (login == 'Admin' || 'User'){ 

need to

 if (login == 'Admin' || login == 'User') { 

 var login = prompt('Введите логин !'); if (login == 'Admin' || login == 'User') { var password = prompt('Введите пароль !'); if (password == '12345') { alert("Добро пожаловать"); } else if (password == null) { alert("Вы уже уходите?"); } else { alert("Go away"); } } else { alert("Who are you?"); }