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!");
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")
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!');
}
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!');
}
}