The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Javascript help once again, please by lemurtx 2002-10-18 06:12:27
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();
[ Reply ]
  Try type casting by Y2KDragon2002-10-18 06:31:36
    well... by lemurtx2002-10-18 07:04:52
  Try this by bslatner2002-10-18 07:07:12
    Getting closer but... by lemurtx2002-10-18 07:26:12
    heh-heh oops by lemurtx2002-10-18 08:25:43
  add *1 to force cast by tigermouse2002-10-18 08:25:09
    woo-hoo! by lemurtx2002-10-18 08:30:23
      I would suggest that ToFixed is the culprit. by Naruki2002-10-18 15:47:51

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)