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

136
Views
How to allow unlimited password attempts in javascript

var password;
    var pass1="administrator";
    password=prompt('Please enter password',' ');
    if (password!=pass1)
        alert('password is not currect');

    else
        {
            window.location="home.html";
        }

I want to make the number of attempts on the password unlimited

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

If you want to keep prompting until they get it, you can use a do...while

var password;
var pass1 = "administrator";
do {
  password = prompt('Please enter password', '');
  if (!password) break
  if (password === pass1) {
    window.location = "home.html";
    break; // stop
  } 
  alert('password is not correct');
} while (password != pass1)

If you just want them to be allowed to reload and try again

var password;
var pass1 = "administrator";
password = prompt('Please enter password', ' ');
if (password != pass1)
  alert('password is not correct');
else {
  window.location = "home.html";
}

about 4 years ago · Juan Pablo Isaza Report

0

remove the else part from your code.

var password;
var pass1="administrator";
password = prompt('Please enter password',' ');
if (password!=pass1)
    alert('password is not currect');
about 4 years ago · Juan Pablo Isaza Report

0

Use this code and add breaking statement as you wish to break the loop:

while (true) {
  var password;
  var pass1 = "administrator";
  password = prompt('Please enter password', ' ');
  if (password === null) break;
  if (password != pass1)
    alert('password is not currect');
  else {
    window.location = "home.html";
    break;
  }
}

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!