[Solved] Limit sum value after 5 clicks [closed]


Here is one way to do it.

let sum = 0;
let clicks = 0;
$sum = $(".sum");
$clicks = $("#clicks");

$(".combat").on("click", function(){
  if(clicks >= 5) return;
  clicks += 1;
  $clicks.text(`clicks:${clicks}`);
  const $this = $(this);
  const val = parseInt($this.text());
  
  if(sum + val <= 100){
    sum += val;
    $sum.text(`sum:${sum}`);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<table>
   
    <tbody>
        <tr>
            <td class="combat">10</td>
            <td class="combat">15</td>
            <td class="combat">30</td>
            
        </tr>
        <tr>
            <td class="combat">50</td>
            <td class="combat">20</td>
            <td class="combat">50</td>
            
        </tr>
       
    </tbody>
</table>
  
  <div class="sum">sum:</div>
  <div id="clicks">clicks:0</div>
</div>

0

solved Limit sum value after 5 clicks [closed]