javascript – I can't fold the JS

Question:

<script type="text/javascript">
  $(document).ready(function() {
  $(".list tr:even td").css("background-color", "#F4F4F8");
});
  $(document).ready(function() {
  $("input:checkbox").click(function(){
  update_sum();
 });
});

function update_sum(){

var bonus = $('#sum_bonus').val();
var sum = 0;

$('input:checkbox').each(function (){
  if(this.checked){
    sum += (1*$(this).attr('data-sum'));
  }
});
 $("#total_sum").text(sum.toFixed(2));
 $("#bonus").text(sum + bonus);

 }
 </script>

$("#bonus").text(sum + 20); so it turns out to fold, and so
$("#bonus").text(sum + bonus ); but it doesn’t work?

Answer:

$("#bonus").text(sum + bonus);
$("#bonus").text(sum + +bonus);

Though it's better to edit here instead:

var bonus = $('#sum_bonus').val();
var bonus = +$('#sum_bonus').val();
Scroll to Top