Results 1 to 3 of 3

Thread: Help with Javascript assignment

  1. #1
    Join Date
    Nov 2011

    Help with Javascript assignment

    I need to find out whats wrong with this script but I'm having a tough time. I think I could do it from scratch but that's not the assignment. It's supposed to show the date. I think its missing a function or 2.

    <script language="JavaScript">

    var weekDays = newArray();
    weekDays[0] = "Sun";
    weekDays[1] = "Mon";
    weekDays[2] = "Tue";
    weekDays[3] = "Wed";
    weekDays[4] = "Thu";
    weekDays[5] = "Fri";
    weekDays[6] = "Sat";

    var monthnames = new Array();
    monthNames[0] = "Jan";
    monthNames[1] = "Feb";
    monthNames[2] = "Mar";
    monthNames[3] = "Apr";
    monthNames[4] = "May";
    monthNames[5] = "Jun";
    monthNames[6] = "Jul";
    monthNames[7] = "Aug";
    monthNames[8] = "Sep";
    monthNames[9] = "Oct";
    monthNames[10] = "Nov";
    monthNames[11] = "Dec";

    var today = new Date();
    var wkDay = today.getDay();
    var mon = today.getMonth();
    var day = today.getDate();
    var fyear = today.getFullYear();
    var out =weekDays[wkDay] + ", " + monthNames[mon] + " " + day +" " + fyear;

  2. #2
    Join Date
    Nov 2011
    It's "new Array", not "newArray" and have a look at upper and lower case spelling, "monthNames" and not "monthnames".

    Both mistakes can easily be spotted by using any kind of error console by the way.

  3. #3
    Join Date
    Aug 2007
    Both of your actual errors have been pointed out, but as a general note, JSON would lead to cleaner code, even if not appropriate for this assignment.
    var weekDays = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
    var monthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
    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