176k views
2 votes
Validate that the user age field is between 18 and 100. 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.

User Gui Ambros
by
4.4k points

1 Answer

6 votes

Answer:

function userAgeCheck(event){

// if age is in range 18 to 100

// parseInt() converts string into integer

if( parseInt(userAge.value) >= 18 && parseInt(userAge.value) <= 100 ){

// set color to light green

document.body.style.backgroundColor = "green";

userAgeValid = true;

}

else{

// set color to orange

document.body.style.backgroundColor = "orange";

userAgeValid = false;

}

}

Step-by-step explanation:

User Cezary Butler
by
5.1k points