I have this Conditional Statement that I am trying to use shorthand.
As you can see when I get on the else I don't know how to make the passwordMatchError.setAttribute("id", "error")
to show together with the passwordMatchError.textContent = ("Password does not match. Please retype.");
I tried using the signs +, || and && but didnt work.
Can you guys help me out?
Many thanks.
const checkThePassword = (registration) => {
let getTheOriginalPassword = registration.password.value; //assign passwords by value, avoid const here in case of unprotected memory
let getTheRetypedPassword = registration.retypedpassword.value;
// Simple equality check for retyped password
getTheOriginalPassword === getTheRetypedPassword ? passwordMatchError.setAttribute("id", "error") : passwordMatchError.textContent = ("Password does not match. Please retype.");
// false return is done together with error handling
}
Here is the original code
const checkThePassword = (registration) => {
let getTheOriginalPassword = registration.password.value; //assign passwords by value, avoid const here in case of unprotected memory
let getTheRetypedPassword = registration.retypedpassword.value;
// Simple equality check for retyped password
if (getTheOriginalPassword === getTheRetypedPassword) {
return true;
} else {
passwordMatchError.setAttribute("id", "error");
passwordMatchError.textContent = ("Password does not match. Please retype.");
return false; // false return is done together with error handling
}
}
Aucun commentaire:
Enregistrer un commentaire