javascriptsyntax-error

Syntax error code - Java script


Normally My code is working fine. but, I get Syntax error. what is mistake in syntax here?

enter image description here

$(document).ready(function() {
$('.myClass').change(function() {
        var ids = ['first', 'second'];
        var totalCount = ids.reduce((prev, id) => parseInt($(`#${id}-passenger`).val()) + prev, 0);
        var mc = $('input[name="myClass"]:checked  + label').text();
        $('#myTotal').val(totalCount + ' - '+mc);
    });
});

Solution

  • Maybe you have a Javascript version issue and you should try without templating ?

    var totalCount = ids.reduce(function (prev, id) {
        return parseInt($('#' + id + '-passenger').val()) + prev
    }, 0);
    

    Hope it helps.