I have the following javascript code:
score -= Math.round(score * 0.10);
$('.sc').text(score);
$('.score').text('-' + Math.round(score * 0.10));
What does it do? Well lets say I have a div with class sc with score = 456 and I want 10% deducted from this without having decimals.
I use this:
score -= Math.round(score * 0.10); results in 456 – 46 = 410
$('.sc').text(score); makes the div sc show: 410
SO far so good, but I have another div with class: score. In this div I want to show the 46. I thought using $('.score').text('-' + Math.round(score * 0.10)); would show it, but this results in 10% of the 410 and not the 456
So how can I show the 46 as result in the div: .score?
Kind regards,
Maurice
Keep track of the deduction, rather than calculating it multiple times.