Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!