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

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

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 Report

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 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!