I am working with the following JavaScript code:
score -= Math.round(score * 0.10);
$('.sc').text(score);
$('.score').text('-' + Math.round(score * 0.10));
This code is designed to deduct 10% from a given score without any decimals. For example, if we have a div with class "sc" and the score is initially set to 456, we would like to take away 10% from this value.
The following line of code
score -= Math.round(score * 0.10);
calculates that 456 - 46 = 410, and then $('.sc').text(score);
updates the text in the "sc" div to display: 410
However, another div with the class "score" needs to display the deducted amount, which should be 46. Unfortunately, using
$('.score').text('-' + Math.round(score * 0.10));
shows 10% of 410 rather than the original 456.
How can I correctly display the deducted amount (46) in the ".score" div? Any suggestions would be greatly appreciated.
Thank you,
Maurice