6 Replies - 511 Views - Last Post: 17 April 2013 - 02:26 PM

#1 jsnoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-April 13

Problem with a formula

Posted 16 April 2013 - 04:33 PM

Ok so i new to JS and one thing i see is the investment calculators on website
so my buddy gave me a assignment he got a year ago in his js class that made a investment calculator
but i have most of it coded but my problem is the formula for it
this is what i was given
"code a for loop that calculates the future value of an investment"
 future value = future value + (future value * annual rate / 100)

now i have

Investments
Annual interest rate
number of years
Future Value
boxes for numbers

i had tried this line of code
future_value = investment + ((investment * rate /100)*(years));

but it works but not the way it should if i put in

Investment 100000
Annual interest rate 10
years 2 it should come out to 121000 instead of 120000
so really any help would be helpful and appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with a formula

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3392
  • View blog
  • Posts: 9,589
  • Joined: 08-June 10

Re: Problem with a formula

Posted 16 April 2013 - 07:29 PM

Quote

years 2 it should come out to 121000 instead of 120000

but you didnít code it that way.

if you compare both code lines, what difference do you notice (besides that one contains the years)?
Was This Post Helpful? 0
  • +
  • -

#3 jsnoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-April 13

Re: Problem with a formula

Posted 17 April 2013 - 02:11 AM

So i looked at this and try to figure it out the difference beside the years is the future_value
i got it to work but it only does one year cause i didnt put in years as a factor
but ive look at other compound interest calculators on the internet and none of them use for loops
but i do see them use Math.pow or something like that and i have no idea what that is yet so i wont use it
var future_value = investment + (investment *  rate / 100);
	$("future_value").value = future_value.toFixed();

thats what i got for the formula i mean it cant be to hard this is suppose to be basic starting off easy stuff
maybe i'll figure it out sometime later
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3392
  • View blog
  • Posts: 9,589
  • Joined: 08-June 10

Re: Problem with a formula

Posted 17 April 2013 - 02:39 AM

View Postjsnoob, on 17 April 2013 - 11:11 AM, said:

ive look at other compound interest calculators on the internet and none of them use for loops
but i do see them use Math.pow or something like that and i have no idea what that is yet so i wont use it

let me put it this way: why using a loop, when a simple formula can solve it as well?


View Postjsnoob, on 17 April 2013 - 11:11 AM, said:

i got it to work but it only does one year cause i didnt put in years as a factor

using only one year causes a (that) certain difference between those two codes not to cause any effect. maybe it helps if you describe in words/sentences each step that the code is supposed to do.
Was This Post Helpful? 0
  • +
  • -

#5 jsnoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-April 13

Re: Problem with a formula

Posted 17 April 2013 - 10:31 AM

i figured it out with simple math equation so i guess this topic is closed
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3392
  • View blog
  • Posts: 9,589
  • Joined: 08-June 10

Re: Problem with a formula

Posted 17 April 2013 - 11:36 AM

would you like to share the solution with us?
Was This Post Helpful? 0
  • +
  • -

#7 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 782
  • View blog
  • Posts: 1,663
  • Joined: 30-January 09

Re: Problem with a formula

Posted 17 April 2013 - 02:26 PM

I'm guessing it was:
future_value = investment * ((1 + rate /100)^(years));


...in case anyone googles this in future.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1