Find the best solutions to your questions at Westonci.ca, the premier Q&A platform with a community of knowledgeable experts. Join our platform to connect with experts ready to provide precise answers to your questions in different areas. Get quick and reliable solutions to your questions from a community of experienced experts on our platform.

Validate that the user age field is at least 21 and at most 35. If valid, set the background of the field to LightGreen and assign true to userAgeValid. Otherwise, set the background to Orange and userAgeValid to false.HTML JavaScript 1 var validColor-"LightGreen"; 2 var invalidColor"Orange" 3 var userAgeInput -document.getElementByIdC"userAge"); 4 var formWidget -document.getElementByIdC"userForm"); 5 var userAgeValid - false; 7 function userAgeCheck(event) 10 11 function formCheck(event) 12 if (luserAgeValid) { 13 14 15 16 17 userAgeInput.addEventListener("input", userAgeCheck); 18 formWidget.addEventListener('submit', formCheck); event.preventDefault); 3 Check Iry again

Sagot :

Answer:

Explanation:

The code provided had many errors. I fixed the errors and changed the userAgeCheck function as requested. Checking the age of that the user has passed as an input and changing the variables as needed depending on the age. The background color that was changed was for the form field as the question was not very specific on which field needed to be changed. The piece of the code that was created can be seen in the attached image below.

var validColor = "LightGreen";

var invalidColor = "Orange";

var userAgeInput = document.getElementById("userAge");

var formWidget = document.getElementById("userForm");

var userAgeValid = false;

function userAgeCheck(event) {

   if ((userAgeInput >= 25) && (userAgeInput <= 35)) {

       document.getElementById("userForm").style.backgroundColor = validColor;

       userAgeValid = true;

   } else {

       document.getElementById("userForm").style.backgroundColor = invalidColor;

       userAgeValid = false;

   }

};

function formCheck(event) {};

if (!userAgeValid) {

   userAgeInput.addEventListener("input", userAgeCheck);

   formWidget.addEventListener('submit', formCheck);  

   event.preventDefault();

}

View image sandlee09