Hi I am trying to have the event listener below update the variable auth to true if the user enters the right password. However, when I run the file and do the submission the variable auth is not updated.
auth = false;
//For the event listeners
console.log(auth)
console.log("current value of auth variable is: ")
console.log(auth);
// first we need to grabe the value that the user enters
const password = document.getElementById("password")
const ourform = document.getElementById("simplepwform");
ourform.addEventListener('submit', (e) => {
if (password.value === 'apw') {
auth = true;
console.log(auth);
alert("That's right. Check the value of the auth variable in console.")
} else {
alert("Wrong password. Please try again.")
}
})
<div class="center">
Form practice
</div>
<div id="simplepwform">
<form method="GET">
<input id="password" , name="password">
</form>
</div>
I tried the above and was expecting that after entering the right password then auth would be updated.