www.webdeveloper.com
Results 1 to 2 of 2

Thread: JavaScript help please.

  1. #1
    Join Date
    Jul 2009
    Location
    Aberdeen
    Posts
    1

    JavaScript help please.

    I need to create a variable named today and assign it the result of creating a date object. How do I do that please?
    <HTML>
    <HEAD>
    <TITLE>Lab 6-4</TITLE>

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    // Create Date object



    var monthName = new Array();
    monthName[0] = "January";
    monthName[1] = "February";
    monthName[2] = "March";
    monthName[3] = "April";
    monthName[4] = "May";
    monthName[5] = "June";
    monthName[6] = "July";
    monthName[7] = "August";
    monthName[8] = "September";
    monthName[9] = "October";
    monthName[10] = "November";
    monthName[11] = "December";

    var myYear = today.getYear();
    if (myYear < 2000) myYear = myYear + 1900;

    var myDate = today.getDate();
    var dayExt = "th";

    if ((myDate == 1) || (myDate == 21) || (myDate == 31)) dayExt = "st";
    if ((myDate == 2) || (myDate == 22)) dayExt = "nd";
    if ((myDate == 3) || (myDate == 23)) dayExt = "rd";

    var extDate = myDate + dayExt;

    alert("The month number is: " + (today.getMonth() + 1));
    alert("The date number is: " + today.getDate());
    alert("The year number is: " + today.getYear());

    // -->
    </SCRIPT>

    </HEAD>
    <BODY>
    <H3>CIW Web Languages</H3>
    <HR>
    <H4>Today is the

    <SCRIPT LANGUAGE="JavaScript">
    <!--

    document.write(extDate + " day of ");
    document.write(monthName[today.getMonth()] + " in the year ");
    document.write(myYear + ".");

    // -->
    </SCRIPT>
    </H4>

    </BODY>
    </HTML>

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles