Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

292
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda