0

Can someone check my code?

In the for loop x1 gets set to a random number and I can’t figure out why could someone help me please?

18th Mar 2018, 9:36 AM
Type
Type - avatar
3 Answers
+ 4
Because your passed in values are strings, you concatenate a instead of add each time in the loop.
18th Mar 2018, 11:42 AM
John Wells
John Wells - avatar
+ 1
Thanks! I used the parse function and it works now!
18th Mar 2018, 12:33 PM
Type
Type - avatar
0
//calling the function in window.onload to make sure the HTML is loaded var x; var y; var z; x = prompt("Input your amount of money"); y = prompt("Input the interest rate"); z = prompt("Type the number of years"); var final = interest(x, y, z); alert(final); function interest(x1, y1, z1){ var a = x1; var rate = (1+(y1/100)); x1 = x1 * rate; for(i=1; i < z1; i++){ x1 = (x1 + a)* rate; } return x1; }
18th Mar 2018, 9:37 AM
Type
Type - avatar