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?
3 Answers
+ 4
Because your passed in values are strings, you concatenate a instead of add each time in the loop.
+ 1
Thanks! I used the parse function and it works now!
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;
}