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

Example 6.10:
Boolean Operators


Click on the button to use nested if statements combined with Boolean operators to tell you if it's Friday afternoon, a weekend day, or a weekday:


This is the script we used. First, this in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var dToday = new Date() var nHours = dToday.getHours() var nDay = dToday.getDay() if ((nDay == 5) && (nHours >= 12)) { alert("Thank God it's Friday afternoon" ) } else { if ((nDay == 6) || (nDay == 0) ) { alert("Hey, it's the weekend" ) } else { alert("Just another day") } } } //--> </SCRIPT> With this button: <form> <input type="button" value="What day is it?" onclick="function1()"> </form>
Previous Example-|-Next Example-|-Return to Chapter Listing