TAXES

TECHNOLOGY

SERVICES

CRYSTAL COMPUTER CONCEPTS

DELAWARE'S   ·      MIDDLETOWN  ·     ODESSA  ·    TOWNSEND AREA

The purpose of this illustration is twofold:

  1. Present a simple IF STATEMENT.
  2. Show the Conditional Operator.
  3. Remember: each and every statement must end with a semicolon--.
  4. A value is assigned to a variable based on the execution of the condition.
  5. The getDate() method retrives the day of the month.
  6. The getDay() method retrives the day of the week
    starting with Sunday initialized as a zero.

This example demonstrates the If statement. A simple comparison is made. Action is only specified if the condition is true.

If the time on your browser is less than 12, you will get a "Good morning" greeting.

Next the date refering to the day of the month is given.

Finally, the Conditional Operator returns its value which is either Saturday or not.


The script for all this is as follows:
<script type="text/javascript">

var d =new Date();

var time = d.getHours();
var num_day = d.getDate();//This is the date of the month.
var day = d.getDay();//This is number for day of week.
if (time < 12) 
  {
  document.write("Good morning");
  }

day=(day==6)?"It's Saturday":"It's NOT Saturday!";//This is an coditional operator.

The calls are writen as follows between script tags:

document.write("The day of the month is: " + num_day +"."+ "<br />"); document.write(day + "<br />"); </script>

Return to Table of Contents


DELAWARE'S MIDDLETOWN ODESSA AND TOWNSEND AREA