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

295
Visualizações
enter a password if 3 time wrong attempt If the user enters two incorrect passwords, but was able to provide the correct password for the 3rd time

can anyone help me with this im just starting to learn JS Create a program that will exit if the user enters an incorrect password thrice//If the user enters two incorrect passwords, but was able to provide the correct password for the 3rd time, reset your counter variable into 0

//3 incorrect enter of password, add alert("Your account has been blocked!"); heres what i have done so far

const userPass = "Password123";
let inputPass = prompt("Please enter your password:");
let counter = 0;

while (inputPass != userPass) {
    inputPass = prompt("Please enter your password:");
}

console.log("Thank you for providing the right password!");
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

const userPass = "Password123";
let inputPass = prompt("Please enter your password:");
let counter = 0;

while (inputPass != userPass && counter <3) {
    inputPass = prompt("Please enter your password:");
    counter++
}

if(counter < 3) console.log("Thank you for providing the right password!");
else console.log("Your account is blocked")
about 4 years ago · Juan Pablo Isaza Relatório

0

is this what you are looking for? https://jsfiddle.net/8e2k0ymh/

const userPass = 'Password123';
let inputPass = prompt('Please enter your password:');
let counter = 0;

while (inputPass != userPass && ++counter < 3) {
    inputPass = prompt('Please enter your password:');
}
if (counter == 3) {
    alert('Your account has been blocked!');
} else {
    alert('Thank you for providing the right password!');
}
about 4 years ago · Juan Pablo Isaza Relatório

0

I would run an if statement after submitting the password that checks to see if the password is correct. If not correct add to counter and check if the counter is equal to 3.

if (inputPass != userPass) {
  counter++;
  if (counter >= 3) {
    inputPass = prompt('You have been blocked!');
  }
}

about 4 years ago · Juan Pablo Isaza 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