javascript - Why are extra cells being added to my calendar between the days of the week? -


so javascript course, our book walks through creation of calendar. thought copied appeared in book, maybe not. reason, blank cells being inserted between names of days of week. should not happen. doing wrong?

this full script:

<html>     <head>         <title>web 240 assignment 3</title>         <style type="text/css">             table {                 background: #ccc;                 border: 1px solid #999;                 padding: 3px;             }             #calendar_head {                 background: red;                 color: white;                 font-weight: bold;                 text-align: center;             }             .calendar_weekdays {                 background: white;                 border-bottom: 5px solid #ccc;                 font-weight: bold;             }             .calendar_dates {                 background: white;                 padding: 5px 25px 10px 5px;             }         </style>         <script type="text/javascript">             function calendar(){                  document.write('<table id="calendar_table">');                  var caldate = new date();                 writecaltitle(caldate);                 writedaynames();                 writecaldays(caldate);                  document.write('</table>');             }             function writecaltitle(calendarday){                  var monthname = new array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");                  var thismonth = calendarday.getmonth();                 var thisyear = calendarday.getfullyear();                  document.write("<tr>");                 document.write('<th id="calendar_head" colspan="7">');                 document.write(monthname[thismonth] + " " + thisyear);                 document.write('</th>');                 document.write('</tr>');             }              function writedaynames(){                  var dayname = new array("sun", "mon", "tue", "wed", "thu", "fri", "sat");                 document.write('<tr>');                  for(var = 0; < dayname.length; i++){                      document.write('<th class="calendar_weekdays">' + dayname[i] + "<th>");                  }                  document.write("</tr>");              }              function daysinmonth(calendarday){                  var thisyear = calendarday.getfullyear();                 var thismonth = calendarday.getmonth();                 var daycount = new array(31, 28, 31, 30, 31, 30, 31,31, 30, 31, 30, 31);                  if(thisyear % 4 == 0){                      if((thisyear % 100 != 0) || (thisyear % 400 == 0)){                          daycount[1] = 29;                      }                  }                  return daycount[thismonth];              }              function writecaldays(calendarday){                  var daycount = 1;                 var totaldays = daysinmonth(calendarday);                  calendarday.setdate(1);                 var weekday = calendarday.getday();                  document.write('<tr>');                 for(var = 0; < weekday; i++){                      document.write('<td></td>');                  }                  while(daycount <= totaldays){                      if(weekday == 0) document.write('<tr>');                     document.write('<td class="calendar_dates">' + daycount + "</td>");                     if(weekday == 6) document.write('</tr>');                      daycount++;                     calendarday.setdate(daycount);                     weekday = calendarday.getday();                  }              }         </script>      </head>     <body>         <script type="text/javascript">calendar();</script>     </body> </html> 

this output: http://imgur.com/bzdxm1r

thanks time!


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -