Previous Example-|-Next Example-|-Return to Chapter Listing

Example 6.9:
Nesting if Statements


Click on the button to use nested if statements to tell you if it's Saturday, Sunday, or a weekday:


This is the script we used. First, this in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var dToday = new Date() var nDay = dToday.getDay() if (nDay == 0) { alert("It’s Sunday") } else { if (nDay <= 5) { alert("It's a week day") } else { alert("Hey, it's Saturday") } } } //--> </SCRIPT> With this button: <form> <input type="button" value="What day is it?" onclick="function1()"> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing