Java Reference
In-Depth Information
<body>
<script>
var myAge = parseInt( prompt("Enter your age", 30), 10 );
if (myAge >= 0 && myAge <= 10) {
document.write("myAge is between 0 and 10<br />");
}
if ( !(myAge >= 0 && myAge <= 10) ) {
document.write("myAge is NOT between 0 and 10<br />");
}
if ( myAge >= 80 || myAge <= 10 ) {
document.write("myAge is 80 or above OR 10 or below<br />");
}
if ( (myAge >= 30 && myAge <= 39) || (myAge >= 80 && myAge <= 89) ) {
document.write("myAge is between 30 and 39 or myAge is " +
"between 80 and 89");
}
</script>
</body>
</html>
When you load it into your browser, a prompt box should appear. Enter the value 30 , then press
Return, and the lines shown in Figure 3-6 are written to the web page.
figure 3-6  
The script block starts by defining the variable myAge and initializing it to the value entered by the user
in the prompt box and converted to a number:
var myAge = parseInt( prompt("Enter your age", 30), 10 );
After this are four if statements, each using multiple conditions. You look at each in detail in turn.
Search WWH ::




Custom Search