0

By clicking button, I would like to have: - 1 prompt to enter my password - IF correct -> goes to a page, if not: -2nd prompt -> if correct password -> goes to a page, if not: -3rd prompt -> if correct password -> goes to page, if not:

alert('you failed')

Currently it doesen't read the 2nd prompt, nor it makes the final alert.

The code:

function passWord() {
var number = 0;
var pass1 = prompt('Give password','your password...... ');
while (number < 3) {




if (pass1=="montpellier") {
        alert('Success.... you're being redirected');
        window.open("quiz.php");

    } else {
        number =+ 1;
        var pass2=prompt('Try again','paassword....');
        if (pass2=="montpellier & number < 3) {
            alert('Success....you'rebeing redirected');
        window.open("quiz.php");
        } else {
            alert('You failed');
            window.history.back();
    }
}
}

When I try to enter the password on the second prompt, it just continues to make prompts until number < 3.

Nikola Stoilov
  • 85
  • 1
  • 10
  • Some of the problem you're having may be due to your string encasing. Since you have an apostrophe in the string, try using quotation marks to encase it instead. – 0x2A Dec 07 '17 at 20:09
  • Look at the syntax highlighting on this page - it should be clear there is some invalid syntax. `alert('Success....you're being redirected');` Where does this String start and end? Where is it _supposed_ to start and end? – takendarkk Dec 07 '17 at 20:10
  • I actually even tried it with `alert("Success..you'rebeing redirected");` and it still doesen't work correctly. – Nikola Stoilov Dec 07 '17 at 20:14
  • This is the edited code which actually works as intended: `function passWord() { var number = 1; var pass1 = prompt('Please type the password in order to proceed:','type your password....'); if (pass1=="123") { alert('This is correct, you can proceed.'); window.open('quiz.php'); } while (number < 3 & pass1 != "123") { number = number + 1; pass1 = prompt("Wrong ! Try again !"); if (pass1=="123") { alert("You're good to go!"); window.open("quiz.php"); } else if (number==3) { alert('Try again'); window.history.back(); } } }` – Nikola Stoilov Dec 07 '17 at 20:32

0 Answers0