tell me there is a formula

a * b / 12 / 100 = result 

I need to use this formula 12 times (repetition).

That is, the result of the first formula is used in the following for addition with а :

 1) a * b / 12 / 100 = result 2) (a + result) * b / 12 / 100 = result 3) (a + result) * b / 12 / 100 = result 4) (a + result) * b / 12 / 100 = result 

Etc.

In this case, the number of repetitions may vary.

How to implement it?

  • one
    Maybe cycles will help? - MBo
  • Yes, but how in the cycle to use the result of the first formula in the following - Kalnaus Vladislav
  • At the beginning, result = 0 - MBo

1 answer 1

 const times = 4; // вместо result будем использовать c const foo = (a, b, с) => (a + с) * b / 12 / 100; const a = 10; // случайные значения const b = 20; // случайные значения let result = 0; // Используем цикл, для повторного выполнения функции for(let i = 0; i < times; i++) { result = foo(a, b, result) } console.log(result) 

  • With each repetition, does it overwrite the result? - Kalnaus Vladislav
  • It turns out not the correct calculation. With the formula (1000000 + result) * 0.15 / 12 The first 2 values ​​are correct and 3 4 it turns out some kind of game. I can not understand what 12500 12656.25 12658.203125 12658.2275390625 should be 12500 12656.25 12814,453125 12974,6337890625 - Kalnaus Vladislav
  • Yes, overwrites. The formula is the same every time you write it - ThisMan