Ricky - 1 year ago 58

Javascript Question

I am trying to add the given percentage onto a number that already has that percentage added on.

I.e, The user defines 25% (this is not set could be any number percentage) I then add 25% onto the amount they invested to start with so for example:

Customer invests £10,000, I add 25% onto £10,000, which equals £12,500. **AND THEN** the following month I add the 25% onto the £12,500 from the month before, which should equal £15,625.

Yet for all my overthinking i believe i have over complicated things in my head. It should be a case of simple maths, yet i cannot figure this out in Javascript.

I keep getting the value of £15,000, and cannot work out how to store the given percentage in a variable itself and then add that percentage onto the Total amount.

I really have spent far too long overthinking this and suppose it is really simple, but i have hit a wall now.Please only answer in Javascript, Not Jquery.

Here is some code.

`// Set the values...`

Num = prompt("Enter a percentage using a decimal Number...");

interestRate = Num*100;

startCash = 10000;

total = startCash*interestRate/100+startCash;

month = 1;

// Inputting Text...

StartText = "Starting Money: £";

IntText = "Interest Earned: ";

TotalText = "Total Amount: £";

MonthText = "Month: ";

displayStart = StartText + startCash + "\n";

dispInt = IntText + interestRate + "\n";

dispTotal = TotalText + total + "\n";

dispMonth = MonthText + month + "\n";

dispvalue = displayStart + dispInt + dispTotal + dispMonth;

console.log (dispvalue);

addInt = total + interestRate*100;

console.log (addInt);

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

The total from compound interest calculated for the next month should be

```
addInt = total*interestRate/100 + total;
```

just like the fifth line of your code.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**