title: How can i refactor my JS to use fewer if else statements and be less repetitive
body: <p>The issue i'm facing is this code feels way too repetitive/heavy. I would like to simplify this or refactor to make it better, any suggestions welcome. I am still JS beginner, so thank you for input and explanations.</p>
  <p>The goal of this code is to change the position of my side navigation based on where the user is on the page. Here's the code:</p>
  <pre><code>/** Position for side navigation when page has hero carousel AND subnav */
  if (heroCarousel &amp;&amp; subNav) {
      // Changes position for side navigation based on user scroll
      let positionChanges = function positionChangesOnScroll() {
          // Define variables
          var toTop = $(window).scrollTop(),
              elementOffset = $('footer').offset().top,
              distance = (elementOffset - toTop),
              jumpNav = $('.jn-publish');
          // Bahavior for side navigation on page load
          if (toTop &lt; 200 ) {
              // Adding class for first position
              jumpNav.addClass('pos1-carousel-subnav');
          }
          // Bahavior for side navigation immediatly after sub navigation sticks
          if (toTop &gt;= 200 &amp;&amp; toTop &lt; 330 ) {
              // Adding class for second position
              jumpNav.addClass('pos2-carousel-subnav');
          } else {
              jumpNav.removeClass('pos2-carousel-subnav');
          }
          // Behavior for side navigation (fixed) when page content scrolss
          if (toTop &gt;= 330 &amp;&amp; distance &gt; 380) {
              // Adding class for fixed position
              jumpNav.addClass('pos3-carousel-subnav');
          } else {
              jumpNav.removeClass('pos3-carousel-subnav');
          }
          // Stop fixed position at footer
          if (distance &lt;= 380) {
              // Adding class for fadding out nav at footer position
              jumpNav.addClass('pos4-carousel-subnav');
          } else {
              jumpNav.removeClass('pos4-carousel-subnav');
          }
      };
      /** Executes functions during events 'load' and 'scroll,' */
      window.addEventListener('load', positionChanges);
      window.addEventListener('scroll', positionChanges);
  }
  </code></pre>