Reputation: 5761
The following works fine however it's a static formula:
temp = 1+(value3/100),
result = value4/(temp) + value4/(temp * temp) + value4/(temp * temp * temp);
value3 is a dynamic value coming from the following:
var value3 = document.getElementById('v3').value;
The addition (x3) in the result variable is currently static based on an input value of 3. However if that input value changes to 2 or(any other number) how can i make the formula changing dynamically so that it would match the following?
result = value4/(temp) + value4/(temp * temp); (based on an input of 2)
result = value4/(temp) + value4/(temp * temp) + value4/(temp * temp * temp) + value4/(temp * temp * temp * temp); (based on an input of 4)
Upvotes: 0
Views: 377
Reputation: 4735
Try this:
var input = 4; // or 2, or 3, this can be anything
var result = 0;
for (var i = 1; i <= input; i++)
{
result += value4 / Math.pow(temp, i)
}
Upvotes: 2