Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

97
Visualizações
How to return to the same condition if the password is wrong twice

When you input wrong password, incorrect alert show, but second time when you do it, it just let you on site.

var password = "Password123";
          var pass = window.prompt("Enter password: ");
          if (pass == sifra) {
            alert("Correct");
          } else {
            var pass = window.prompt("Incorrect password: ");
          }
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

You cause your code has no checks after the second prompt. In this scenario, You should write your code in a kind of recursion way. When the password check fails, It should begin the same process again and again until it passes.

// fn: verify the password
function verifyPassword(pass) {
  if (pass === "sifra") {
    alert("Correct");
  } else {
    // prompt the password again if it's incorrect
    promptPassword("Incorrect password: ");
  }
}

// fn: promoting the password
function promptPassword(msg = "Enter password:") {
  var pass = window.prompt(`${msg} `);

  // verify the password
  verifyPassword(pass);
}

promptPassword();

about 4 years ago · Santiago Gelvez Relatório

0

This is happening because second time its just taking input but not validating password if you want to validate password untill its correct you can try this just add a loop

var pass = window.prompt("Enter password: ");
while (pass !== sifra) {
  pass = window.prompt("incorrenct password try again: ");
}
// reaches here only when password is corrent
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda