JSCalc for loop statement
up vote
-1
down vote
favorite
Javascript beginner
Trying to create a compound calculator, but then it only displays one row (year, investment value). How do I get the calculator to display table of investment values from year 1 to year n?
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
return
returnz:[
'years' : yr,
'returnValue': inputs.value*(Math.pow((1+ir),yr))
]
;
The webpage:
https://jscalc.io/calc/OaVdNdV6sRENdT66
Thank you!
javascript
New contributor
add a comment |
up vote
-1
down vote
favorite
Javascript beginner
Trying to create a compound calculator, but then it only displays one row (year, investment value). How do I get the calculator to display table of investment values from year 1 to year n?
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
return
returnz:[
'years' : yr,
'returnValue': inputs.value*(Math.pow((1+ir),yr))
]
;
The webpage:
https://jscalc.io/calc/OaVdNdV6sRENdT66
Thank you!
javascript
New contributor
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Javascript beginner
Trying to create a compound calculator, but then it only displays one row (year, investment value). How do I get the calculator to display table of investment values from year 1 to year n?
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
return
returnz:[
'years' : yr,
'returnValue': inputs.value*(Math.pow((1+ir),yr))
]
;
The webpage:
https://jscalc.io/calc/OaVdNdV6sRENdT66
Thank you!
javascript
New contributor
Javascript beginner
Trying to create a compound calculator, but then it only displays one row (year, investment value). How do I get the calculator to display table of investment values from year 1 to year n?
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
return
returnz:[
'years' : yr,
'returnValue': inputs.value*(Math.pow((1+ir),yr))
]
;
The webpage:
https://jscalc.io/calc/OaVdNdV6sRENdT66
Thank you!
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
return
returnz:[
'years' : yr,
'returnValue': inputs.value*(Math.pow((1+ir),yr))
]
;
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
return
returnz:[
'years' : yr,
'returnValue': inputs.value*(Math.pow((1+ir),yr))
]
;
javascript
javascript
New contributor
New contributor
edited Nov 9 at 15:20
New contributor
asked Nov 9 at 15:11
okay_picture
11
11
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The value that you're returning in returnz is a list that has only one element, containing the last year and its associated interest rate.
You need to initialize an empty list and add each year with a for loop:
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
var years = ;
for(var year = 1; year <= yr; year++)
years.push(
'years' : year,
'returnValue': inputs.value*(Math.pow((1+ir), year))
);
return
returnz: years
;
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The value that you're returning in returnz is a list that has only one element, containing the last year and its associated interest rate.
You need to initialize an empty list and add each year with a for loop:
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
var years = ;
for(var year = 1; year <= yr; year++)
years.push(
'years' : year,
'returnValue': inputs.value*(Math.pow((1+ir), year))
);
return
returnz: years
;
add a comment |
up vote
0
down vote
The value that you're returning in returnz is a list that has only one element, containing the last year and its associated interest rate.
You need to initialize an empty list and add each year with a for loop:
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
var years = ;
for(var year = 1; year <= yr; year++)
years.push(
'years' : year,
'returnValue': inputs.value*(Math.pow((1+ir), year))
);
return
returnz: years
;
add a comment |
up vote
0
down vote
up vote
0
down vote
The value that you're returning in returnz is a list that has only one element, containing the last year and its associated interest rate.
You need to initialize an empty list and add each year with a for loop:
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
var years = ;
for(var year = 1; year <= yr; year++)
years.push(
'years' : year,
'returnValue': inputs.value*(Math.pow((1+ir), year))
);
return
returnz: years
;
The value that you're returning in returnz is a list that has only one element, containing the last year and its associated interest rate.
You need to initialize an empty list and add each year with a for loop:
'use strict';
var ir=inputs.interestRate/100;
var yr=inputs.years;
var years = ;
for(var year = 1; year <= yr; year++)
years.push(
'years' : year,
'returnValue': inputs.value*(Math.pow((1+ir), year))
);
return
returnz: years
;
answered Nov 9 at 15:23
Locoluis
54337
54337
add a comment |
add a comment |
okay_picture is a new contributor. Be nice, and check out our Code of Conduct.
okay_picture is a new contributor. Be nice, and check out our Code of Conduct.
okay_picture is a new contributor. Be nice, and check out our Code of Conduct.
okay_picture is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228346%2fjscalc-for-loop-statement%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password