In: Computer Science
needing assistance with writing an HTML doc with
JavaScript.
Making and Age range calculator
-two independent buttons on the screen. Each button will ask them for their age.
A teenager is someone who is ages 13 to 19. Someone who is younger or older than this age range is not a teenager.
•The first button will check to see if someone is a teenager. This should use a logical AND operator.
•The secons button will check to see if someone is NOT
a teenager. This should use a logical OR operator.
HTML & Javascript Code:
<html>
<head>
<script
type="text/javascript">
//Function that
checks for teenager
function
checkTeenager()
{
//Reading age from user
var age = parseInt(prompt("Please enter your
age: ", "0"));
//Checking age
if(age>=13 && age<=19)
{
alert("You are a
teenager");
}
else
{
alert("You are not a
teenager");
}
}
//Function that
checks for not a teenager
function
checkNotTeenager()
{
//Reading age from user
var age = parseInt(prompt("Please enter your
age: ", "0"));
//Checking age
if(age<13 || age>19)
{
alert("You are not a
teenager");
}
else
{
alert("You are a
teenager");
}
}
</script>
</head>
<body>
<input type="button"
value="Check for Teenager"
onclick="checkTeenager()">      
<input type="button"
value="Check for Not a Teenager"
onclick="checkNotTeenager()">
</body>
</html>
__________________________________________________________________________________________
Sample Run: