Assignment 017a

If-Else

This Web page prompts visitors for their age. Once the age is entered, it is sent to a JavaScript function located in the head of the Web page. Depending on the age of the user, the function creates a response appropriate for the age entered. The response is displayed below:

Here's the code used to create the function in the head section of the Web page:

<script language="Javascript" type="text/javascript">

function checkage(age)
{
if (age<=6)
{
window.document.write("<h2>You're a little one and probably an idiot.</h2>");
}
else
{
window.document.write("<h2>You're over the hill! Get a job!</h2>");
}
}
</script>

Here's the code used to prompt users for their age (located in the body of the document):

<script language="Javascript" type="text/javascript">

//declare variable to capture age of user
var age;

//ask users how old they are
age=prompt("How old are you?", "");

//call function to check age and create iframe
checkage(age);

</script>