title: Javascript calendar - day starting point
body: <p>I'm creating my own calendar in javascript and jQuery.</p>
  
  <p>I've already created it, however I'm stuck at the point, where calendar first day should start for example - on Friday (depending on a day when it actually starts).</p>
  
  <p><strong>I need to also implement that somehow in my calendar, but i get confused in loops.</strong></p>
  
  <p>So far I've created something like this, which takes args month and year to create custom month.</p>
  
  <p><a href="https://i.stack.imgur.com/o5Fmw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o5Fmw.png" alt="enter image description here"></a></p>
  
  <p>The code is here:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var Calendar = {
    customDate: function(date) {
      return new Date(date)
    },
    currentDay: function() {
      return new Date().getDay();
    },
    currentMonth: function() {
      return new Date().getMonth() + 1;
    },
    currentYear: function() {
      return new Date().getFullYear();
    },
    getMonthDays: function(year, month) {
      return new Date(year, month, 0).getDate();
    },
    currentMonthDays: function() {
      return this.getMonthDays(this.currentYear(), this.currentMonth());
    }
  };
  
  Calendar.createCustomCalendar = function(month, year) {
    var currentDays = Calendar.getMonthDays(year, month),
      day = 1,
      monthDay = Calendar.currentDay(month, year),
      calendar = jQuery('.calendar'),
      table = calendar.find('table');
  
    calendar.prepend('&lt;h2&gt;' + month + ' ' + year + '&lt;/h2&gt;');
  
    for (var row = 1; row &lt;= Math.ceil(currentDays / 7); row++) {
      var tableRow = jQuery('&lt;tr class="calendarRow"&gt;&lt;/tr&gt;');
  
      for (col = 1; col &lt;= 7 &amp;&amp; day &lt;= currentDays; col++, day++) {
        jQuery(tableRow).append('&lt;td&gt;' + day + '&lt;/td&gt;');
      }
  
      table.append(tableRow);
    }
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="calendar"&gt;
    &lt;table&gt;
      &lt;tr&gt;
        &lt;th&gt;
          &lt;h4&gt;PON&lt;/h4&gt;
        &lt;/th&gt;
        &lt;th&gt;
          &lt;h4&gt;WTO&lt;/h4&gt;
        &lt;/th&gt;
        &lt;th&gt;
          &lt;h4&gt;SRO&lt;/h4&gt;
        &lt;/th&gt;
        &lt;th&gt;
          &lt;h4&gt;CZW&lt;/h4&gt;
        &lt;/th&gt;
        &lt;th&gt;
          &lt;h4&gt;PIĄ&lt;/h4&gt;
        &lt;/th&gt;
        &lt;th&gt;
          &lt;h4&gt;SOB&lt;/h4&gt;
        &lt;/th&gt;
        &lt;th&gt;
          &lt;h4&gt;NIE&lt;/h4&gt;
        &lt;/th&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Hope you can help me </p>