It appears that "principle" is seen as a string. I'm sure it's something very obvious. I looked over the advice I got last time. Why are my other variables coming out right but principle isn't? I've tried using 0.0 instead of 0, and it doesn't seem to make a difference.
Thank you, once again.
var principle = 0;
var rate = 0;
var interest = 0;
var totalInterest = 0;
function calculate() {
principle = prompt("Please enter your savings amount")
document.writeln("Your savings amount is " + principle)
rate = prompt("Please enter interest rate")
document.writeln("Your interest rate is " + rate + "%")
rate = rate/100
interest = (principle * rate) * 1/12.0
totalInterest = interest * 12
totalSavings = principle + totalInterest.toFixed(2)
document.writeln("Annual interest is " + totalInterest.toFixed(2))
document.writeln("Total savings after one year is " + totalSavings)
getResponse();
}
function getResponse () {
response = prompt("Would you like the program to calculate the annual interest and total savings after one year?","Type yes or no");
if (response === "no")
document.writeln("Thanks for stopping by.");
if (response == "yes")
calculate();
}
getResponse(); |