Как я могу продолжить цикл? - PullRequest
0 голосов
/ 30 октября 2019

Пользователь вводит свой пароль, пока он не будет правильным. Когда пользователь хочет нажать «Отмена», мы спрашиваем «Вы уверены?»и если ответ «нет», то снова спросите пароль.

Я пытался снова использовать strat, но он не работает = (


var password = "username",
    user_password        ,
    checked = true       ,
    user_password = prompt("Enter your password"),
    checked_confirm      ;

label: while(checked){
    if(user_password == password){
        alert("You are successfully logged in");
        break;
    }
    else if(user_password == null){
        checked_confirm =  confirm("Are you sure you want to cancel authorization?");
        if(checked_confirm){
            alert("You have canceled authorization");
            break;
        }
        else{
            continue lable;
        }
    }
    else{
        user_password = prompt("Enter your password");
    }
}

1 Ответ

0 голосов
/ 30 октября 2019

Запросите пароль в начале цикла и не ломайте `, пока не получите его:

var password = "username",
  user_password,
  checked_confirm;

while (true) {
  user_password = prompt("Enter your password");

  if (user_password == password) {
    alert("You are successfully logged in");
    break;
  } else if (user_password == null) {
    checked_confirm = confirm("Are you sure you want to cancel authorization?");
    if (checked_confirm) {
      alert("You have canceled authorization");
      break;
    }
  } else {
    alert("Wrong password");
  }
}
...