title: Write a program that prompts the user to enter a year and the first day of the year, then displays a calendar by constructing HTML
body: <p>I am new to JavaScript (and mostly new to programming in general). This assignment, as stated in the title, was to take inputs for year and first day of the year via prompt from a user, and construct a calendar in the form of an HTML table.</p>
  
  <p>I got started with code from the same type of problem written in Java, and have <em>translated</em> it; however, I cannot get anything to return to the browser. </p>
  
  <p>My desk and forehead are currently bloody and I would really appreciate any help on what I'm doing incorrectly, and/or missing. </p>
  
  <p>Below are both my js code and html.:</p>
  
  <pre><code>    "use strict";
  function getCalendar(year, day)
  {
          var firstDayOfMonth;
          var result;
  
          //Find a number of the first day
          switch (day) 
          {
              case 0 : firstDayOfMonth = "Sunday"; break;
              case 1 : firstDayOfMonth = "Monday"; break;
              case 2 : firstDayOfMonth = "Tuesday"; break;
              case 3 : firstDayOfMonth = "Wednesday"; break;
              case 4 : firstDayOfMonth = "Thursday"; break;
              case 5 : firstDayOfMonth = "Friday"; break;
              case 6 : firstDayOfMonth = "Saturday"; break;
              default : result = "&lt;p&gt;Error: there is no such day of week&lt;/p&gt;";
          }
  
          //Whether the year is a leap year
          function isLeapYear(year) 
          {
             return ((year % 4 === 0) &amp;&amp; (year % 100 !== 0)) || (year % 400 === 0);
          }
  
  
          //Display the calendar
          for (var month = 1; month &lt;= 12; month++) 
          {
  
              //Proper spacing between months
              if (firstDayOfMonth == 0)
                  result += "&lt;br /&gt;";
              else
                  result += "&lt;br /&gt;&lt;br /&gt;");
  
              //Get name of the month
              var monthString = "";
              switch (month) 
              {
                  case 1  : monthString = "January"; break;
                  case 2  : monthString = "February"; break;
                  case 3  : monthString = "March"; break;
                  case 4  : monthString = "April"; break;
                  case 5  : monthString = "May"; break;
                  case 6  : monthString = "June"; break;
                  case 7  : monthString = "July"; break;
                  case 8  : monthString = "August"; break;
                  case 9  : monthString = "September"; break;
                  case 10 : monthString = "October"; break;
                  case 11 : monthString = "November"; break;
                  case 12 : monthString = "December"; break;
              }
  
  
              //Display the heading of the month  
              result += "&lt;table border='1'&gt;&lt;tr&gt;&lt;th&gt;" + " " + monthString + " " + year + "&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;Sun&lt;/th&gt;&lt;th&gt;Mon&lt;/th&gt;&lt;th&gt;Tue&lt;/th&gt;&lt;th&gt;Wed&lt;/th&gt;&lt;th&gt;Thu&lt;/th&gt;&lt;th&gt;Fri&lt;/th&gt;&lt;th&gt;Sat&lt;/th&gt;&lt;/tr&gt;";
  
              //Find the length of the month
              var length = 30 + ((month + (month / 8.0)) % 2);
              if (month == 2) //Adjust February length
                  if (isLeapYear)
                      length -= 1; //Leap year
                  else
                      length -= 2; //Non-leap year
  
              var counter = 1; //Counter to determine end of the week
  
              //Display blank space before first day
              for (var i = 0; i &lt; firstDayOfMonth; i++) 
              {
                  result += "&lt;td&gt;"  "&lt;/td&gt;";
                  counter++;
              }
  
              //Display days
              for (var day = 1; day &lt;= length; day++) 
              {
                  result += "&lt;td&gt;" + day + "&lt;/td&gt;";
                  result += (counter++ % 7 != 0) ? "  " : "&lt;br /&gt;");
              }
  
              //Determine the first day of the next month
              firstDayOfMonth = (firstDayOfMonth + length) % 7;
  
          }
          result += "&lt;/table&gt;";
      return result;
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
   &lt;head&gt;
   &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
    &lt;title&gt;Calendar&lt;/title&gt;
  &lt;script language="JavaScript" type="text/javascript" src="getCalendar.js"&gt;
  &lt;/script&gt;
   &lt;/head&gt;
  
    &lt;body&gt;
  &lt;script language="JavaScript" type="text/javascript"&gt;
  var yearInt = parseInt(prompt("Enter year", 2016));
  var dayInt = parseInt(prompt("Enter the first day of the year. 0 for Sunday, 1 for Monday, ..., and 6 for Saturday", 5));
  document.writeln(getCalendar(yearInt, dayInt));
  
  &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>