title: How can I change the year to 2023 as I move on to next year's January in my calendar website?
body: <p>I'm creating a Calendar Website where I have displayed &quot;July 2022&quot; as current month/year, but unfortunately, as I click my next or previous buttons to change to the next month/year the year seems to be stuck at 2022 but the month changes accordingly. Any ideas on how to fix this? I would highly appreciate the help!
  Below is my HTML and JS code:</p>
  <pre class="lang-html prettyprint-override"><code>            &lt;div class=&quot;month&quot;&gt;
                  &lt;div class=&quot;previous&quot;&gt;
                      &lt;span&gt;&amp;#10094&lt;/span&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;full-date&quot;&gt;
                      &lt;h2 id=&quot;month&quot;&gt;&lt;/h2&gt;
                      &lt;h3 id=&quot;year&quot;&gt;&lt;/h3&gt;
                      &lt;p&gt;&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;next&quot;&gt;
                      &lt;span&gt;&amp;#10095&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>&quot;use strict&quot;;
  
  const date = new Date();
  let year = date.getFullYear();
  
  const render = () =&gt; {
      date.setDate(1);
  
      const monthDays = document.querySelector(&quot;.date&quot;);
      const lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
      const previousLastDay = new Date(date.getFullYear(), date.getMonth(), 0).getDate();
      const firstDayIndex = date.getDay();
      const lastDayIndex = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDay();
      const nextDays = 7 - lastDayIndex - 1;
      
      const months = [
      
          &quot;January&quot;,
          &quot;February&quot;,
          &quot;March&quot;,
          &quot;April&quot;,
          &quot;May&quot;,
          &quot;June&quot;,
          &quot;July&quot;,
          &quot;August&quot;,
          &quot;September&quot;,
          &quot;October&quot;,
          &quot;November&quot;,
          &quot;December&quot;
      ];
  
      document.querySelector(&quot;.full-date h2&quot;).innerHTML = months[date.getMonth()];
      document.querySelector(&quot;.full-date h3&quot;).innerHTML = year;
      document.querySelector(&quot;.full-date p&quot;).innerHTML = new Date().toDateString();
      
      let days = &quot;&quot;;
      
      for (let x = firstDayIndex; x &gt; 0; x--) {
          days += `&lt;div class=&quot;previous-date&quot;&gt;${previousLastDay - x + 1}&lt;/div&gt;`
      }
      
      for (let i = 1; i &lt;= lastDay; i++){
          if (i === new Date().getDate() &amp;&amp; date.getMonth() === new Date().getMonth()) {
              days += `&lt;div class=&quot;today&quot;&gt;${i}&lt;/div&gt;`;
          } else {
              days += `&lt;div&gt;${i}&lt;/div&gt;`;
          }
      }
      
      for (let g = 1; g &lt;= nextDays; g++) {
          days += `&lt;div class=&quot;next-date&quot;&gt;${g}&lt;/div&gt;`;
      }
      monthDays.innerHTML = days;    
  };
  
  document.querySelector(&quot;.previous&quot;).addEventListener(&quot;click&quot;, () =&gt; {
      date.setMonth(date.getMonth() - 1);
      render();
  });
  
  document.querySelector(&quot;.next&quot;).addEventListener(&quot;click&quot;, () =&gt; {
      date.setMonth(date.getMonth() + 1);
      render();
  });
  
  render();
  
  </code></pre>