JavaScript simple calculation

◇◆丶佛笑我妖孽 提交于 2020-01-11 13:32:11

问题


I'm pretty sure I'm being stupid but why isn't this working!?

form.find( '.per_time' ).on( 'change', function() {
            var price = parseInt( form.find( '.section-price' ).attr('data-price'), 10 ) ;
            var multiplier = parseInt( $( this ).val(), 10 );
            var newprice = (price / 7) * multiplier;
            form.find( '.section-price .price' ).html( newprice )
        })

It's this line I'm concerned about:

var newprice = (price / 7) * multiplier;

The calculation is not dividing by 7, it only calculates price * multiplier?

This code also seems to be dictating what happens but I'm pretty sure it's jsut a shorter version of the above.

n.find(".per_time").on("change",function(){var t=parseInt(n.find(".section-price").attr("data-price"),10),r=parseInt(e(this).val(),10),i=(t/7)*r;n.find(".section-price .price").html(i)})

Thanks for all your help in advance. Here is an example of the input.

(595 / 7) * 10

来源:https://stackoverflow.com/questions/17070186/javascript-simple-calculation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!