Holaaa! Ya que el tema de loops no me habia quedado muy claro decidi practicar un poco con este ejercicio y darle al usuario 3 intentos para ingresar la contrase;a les dejo mi version del ejericio
<meta charset="UTF-8">
<title>Log-in Screen</title>
<h1>Log-in Screen</h1>
<script>
// In this exercise I will try to create a log in screen
function lineBreak() {
document.write("<br>");
};
function printt(quote) {
document.write(quote)
lineBreak();
}
var correctPassword = 2523088;
var correctUser = "Magic";
var userLocked = false;
for(var attempts = 1; attempts <= 3; attempts++){
var user = prompt("Please insert your username");
var password = parseInt(prompt("Please insert your password"))
if(user == correctUser && password == correctPassword ){
alert("Welcome to the system " + correctUser)
printt("Access granted")
break;
}
else {
var remainingAttempts = 3 - attempts;
alert("Incorrect username or password please try again. You have " + remainingAttempts + " attempts left")
}
if(attempts == 3) {
userLocked = true;
}
if(userLocked){
printt("Your username is now locked, please try again later.")
}
}
printt("end")
</script>