Validate that the user age field is at least 21 and at most 35. If valid, set the background of the field to validColor and assign true to userAgeValid. Otherwise, set the background to invalidColor and userAgeValid to false. Note: userAgeInput.value accesses the userAge.
JavaScript:
let validColor = "LightGreen";
let invalidColor = "Orange";
let userAgeInput = document.getElementById("userAge");
let formWidget = document.getElementById("userForm");
let userAgeValid = false;
function userAgeCheck(event) {
// Modify this function to appropriately set the following variables.
userAgeInput.style.background = invalidColor;
userAgeValid = false;
/* Your solution goes here */
}
function formCheck(event) {
if (!userAgeValid) {
event.preventDefault();
}
}
userAgeInput.addEventListener("input", userAgeCheck);
formWidget.addEventListener("submit", formCheck);