Program 3:
Get today's date using the Date class. Print the date, month, and year. If the day is a weekday, print "uh..oh...it is a weekday". If the day is either Saturday or Sunday, print "Great...It is the weekend".
Use the following methods:
getFullYear ( ) - Retrieves the year component of the date as a 4-digit number.
getMonth ( ) - Retrieves the month component of the date as a number from 0 to 11 (0=January, 1=February, etc)
getDate ( ) - Retrieves the day-of-month component of the date as a number from 1 to 31
getDay ( ) - Retrieves the day of the week component of the date as a number from 0 to 6 (0=Sunday, 1=Monday, etc)
Sample code:
The following code prints today's date and month.
<html>
<head>
<title>Write the Date</title>
<script language="JavaScript">
<!-- hide me
// get the date information
//
var today = new Date();
var the_day = today.getDate();
var the_month = today.getMonth();
// correct for the month starting from zero
//
the_month = the_month + 1;
// create the string you want to print
//
var the_whole_date = the_month + "/" + the_day;
// show me -->
</script>
</head>
<body>
Today's date is:
<script language="JavaScript">
<!-- hide me
// write the date
//
document.write(the_whole_date);
// show me -->
</script>
</body>
</html>
Get today's date using the Date class. Print the date, month, and year. If the day is a weekday, print "uh..oh...it is a weekday". If the day is either Saturday or Sunday, print "Great...It is the weekend".
Use the following methods:
getFullYear ( ) - Retrieves the year component of the date as a 4-digit number.
getMonth ( ) - Retrieves the month component of the date as a number from 0 to 11 (0=January, 1=February, etc)
getDate ( ) - Retrieves the day-of-month component of the date as a number from 1 to 31
getDay ( ) - Retrieves the day of the week component of the date as a number from 0 to 6 (0=Sunday, 1=Monday, etc)
Sample code:
The following code prints today's date and month.
<html>
<head>
<title>Write the Date</title>
<script language="JavaScript">
<!-- hide me
// get the date information
//
var today = new Date();
var the_day = today.getDate();
var the_month = today.getMonth();
// correct for the month starting from zero
//
the_month = the_month + 1;
// create the string you want to print
//
var the_whole_date = the_month + "/" + the_day;
// show me -->
</script>
</head>
<body>
Today's date is:
<script language="JavaScript">
<!-- hide me
// write the date
//
document.write(the_whole_date);
// show me -->
</script>
</body>
</html>

