...

View Full Version : 1) Is this code completely wrong 2) Can you find the missing semicolon?



xine78
02-20-2003, 05:11 PM
I am doing my first JS assignment, and it is not compiling with an error "expecting ';' line 20 character 30". I have a semicolon after every statement, so I'm thinking the code must be wrong. The assignment is to add a calendar to a site with the current date highlighted (among other things), so that's what all the date variables are about. I'm not getting anything to show up on the site, and when I try to open calendar.js I get the compile error.

This is the site:
http://jolleygood.com/ECT270/Asgn5/bcc.htm

The calendar.js file contains the following code:
function Calendar(caldate)
{
MonthName=new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

DayName=new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

Calendar_Day=newDate(caldate);

var ThisDay=Calendar_Day.getDate();
var ThisMonth=Calendar_Day.getMonth();
var ThisYear=Calendar_Day.getFullYear();

document.write('<table id="calendar"><tr><th id="calendar_head" colspan="7"> "+MonthName[ThisMonth]+", "+ThisYear+" </th></tr>');

for (i=0; i<=6; i++) {
document.write('<tr><th class="calendar_weekdays"> "+DayName[i]+" </th></tr>');
}

}

Please let me know if you can help!

requestcode
02-20-2003, 05:16 PM
I noticed that your quotes are wrong on your document.write statements. Try changing them to this:
document.write('<table id="calendar"><tr><th id="calendar_head" colspan="7"> '+MonthName[ThisMonth]+', '+ThisYear+' </th></tr>');

for (i=0; i<=6; i++) {
document.write('<tr><th class="calendar_weekdays"> '+DayName[i]+' </th></tr>');

Because you are using single quotes to enclose your text you need to use those when you are including variables. You were using double quotes.

xine78
02-20-2003, 06:17 PM
Still the same error, but thanks for the tip. I thought we had to use single quotes around the whole thing a double quotes on the variables so that it doesn't think the opening quote on the variable is the closing quote on the whole thing. I probably just made that up, though.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum