title: My IF statement stops running when final condition is met
body: <p>I’m currently creating a seating plan. User’s should be able to select up to 3 available tables. After 3 tables are selected, the user should not be able to select anymore.</p>
  <p>At the moment, the user is able to select 4 tables, which I do not want. Also, when 4 tables are selected, the user cannot unselect these tables any longer. Whereas, when the condition hasn’t been met, users can unselect tables.</p>
  <p>Things I’ve tried:</p>
  <ul>
  <li>Playing around with the logical operators.</li>
  <li>Putting the if statement in a function and using return</li>
  </ul>
  <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>const availableTables = document.querySelectorAll('.available');
  
  for (let index = 0; index &lt; availableTables.length; index++) {
    availableTables[index].onclick = () =&gt; {
      if (document.getElementsByClassName('active').length &lt;= 3) {
        if (availableTables[index].classList.contains('active')) {
          availableTables[index].classList.remove('active');
        } else {
          availableTables[index].classList.add('active');
        }
      }
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.active {
    background-color: #00ccbc;
  }
  
  .seating-plan {
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 12px;
    border: solid 1px #e8ebeb;
  }
  
  .seating-plan .grey {
    border-color: #d9d9d9 !important;
  }
  
  .seating-plan .till-door {
    display: flex;
    justify-content: space-between;
    height: auto;
    color: #a9a9a9;
  }
  
  .seating-plan #section-1 {
    height: 10%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    display: flex;
  }
  
  .seating-plan #section-2 {
    height: 80%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .seating-plan #section-2 #section-2-left {
    height: 100%;
    width: 20%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: flex-start;
  }
  
  .seating-plan #section-2 #section-2-left .half-circle {
    width: 35px;
    height: 25px;
    border-top-left-radius: 110px;
    border-top-right-radius: 110px;
    border: solid 1px #00ccbc;
  }
  
  .seating-plan #section-2 #section-2-left .half-circle:nth-child(2) {
    transform: rotate(180deg);
  }
  
  .seating-plan #section-2 #section-2-left .half-circle:nth-child(4) {
    transform: rotate(180deg);
  }
  
  .seating-plan #section-2 #section-2-middle {
    height: 100%;
    width: 180px;
    justify-content: space-evenly;
    flex-wrap: wrap;
    display: flex;
    flex-direction: column;
  }
  
  .seating-plan #section-2 #section-2-middle .square-container {
    display: flex;
    justify-content: space-between;
  }
  
  .seating-plan #section-2 #section-2-right {
    height: 100%;
    width: 20%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: flex-end;
  }
  
  .seating-plan #section-3 {
    height: 10%;
    align-items: center;
    justify-content: center;
    display: flex;
    justify-content: space-between;
  }
  
  .seating-plan .square {
    height: 35px;
    width: 35px;
    border: solid 1px #00ccbc;
  }
  
  .seating-plan .full-circle {
    height: 35px;
    width: 35px;
    border-radius: 50%;
    border: solid 1px #00ccbc;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="seating-plan"&gt;
  
    &lt;div class="till-door"&gt;
      &lt;p&gt;Till&lt;/p&gt;
      &lt;p&gt;Door&lt;/p&gt;
    &lt;/div&gt;
  
    &lt;section id="section-1"&gt;
      &lt;div class="square available"&gt;&lt;/div&gt;
      &lt;div class="square grey"&gt;&lt;/div&gt;
      &lt;div class="square available"&gt;&lt;/div&gt;
      &lt;div class="square available"&gt;&lt;/div&gt;
    &lt;/section&gt;
  
    &lt;section id="section-2"&gt;
      &lt;div id="section-2-left"&gt;
        &lt;div class="half-circle available"&gt;&lt;/div&gt;
        &lt;div class="half-circle grey"&gt;&lt;/div&gt;
        &lt;div class="half-circle available"&gt;&lt;/div&gt;
        &lt;div class="half-circle available"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div id="section-2-middle"&gt;
        &lt;div class="square-container"&gt;
          &lt;div class="square available"&gt;&lt;/div&gt;
          &lt;div class="square available"&gt;&lt;/div&gt;
          &lt;div class="square available"&gt;&lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div class="square-container"&gt;
          &lt;div class="square available"&gt;&lt;/div&gt;
          &lt;div class="square available"&gt;&lt;/div&gt;
          &lt;div class="square grey"&gt;&lt;/div&gt;
        &lt;/div&gt;
  
        &lt;div class="square-container"&gt;
          &lt;div class="square grey"&gt;&lt;/div&gt;
          &lt;div class="square available"&gt;&lt;/div&gt;
          &lt;div class="square available"&gt;&lt;/div&gt;
        &lt;/div&gt;
  
  
      &lt;/div&gt;
      &lt;div id="section-2-right"&gt;
        &lt;div class="full-circle available"&gt;&lt;/div&gt;
        &lt;div class="full-circle available"&gt;&lt;/div&gt;
        &lt;div class="full-circle available"&gt;&lt;/div&gt;
        &lt;div class="full-circle available"&gt;&lt;/div&gt;
      &lt;/div&gt;
    &lt;/section&gt;
  
    &lt;section id="section-3"&gt;
      &lt;div class="full-circle available"&gt;&lt;/div&gt;
      &lt;div class="full-circle available"&gt;&lt;/div&gt;
      &lt;div class="full-circle available"&gt;&lt;/div&gt;
      &lt;div class="full-circle available"&gt;&lt;/div&gt;
    &lt;/section&gt;
  
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>