ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

JavaScript Quick Problem



Ok, im designing a compound interest calculator for university ... im still in the early stages this is my code:

<html>
<title>
</title>
<head>
<script language="JavaScript">

money=prompt("Enter the amount of money you wish to invest (£) :","1000");
interest=prompt("Enter the interest rate & :","2");
payments=prompt("Enter the length of time in months :","12");

</script>

</head>

<body>

<script language="JavaScript">

result=Math.round(money*(Math.pow((1+interest/100),payments))*100/100;
document.write(result);

</script>

</body>
<html>


For the moment... all I want is for it to display the answer just on the page.. just so I know its working and then I can progess to doing the table later.

Basically the line of code:

result=Math.round(money*(Math.pow((1+interest/100),payments))*100/100;

That is the calculation, when that line of code is put into the "head" part of my html documnent, it stops the prompt boxes appearing even though I put it after them"... but when its in the "body" section.. the prompt boxes appear but the answer doesnt.

Any ideas?

Cheers, A very confused bigmaddaz



Oh yea just incase my calulations are wrong... here is the formula im working from:

The formula to calculate compound interest is:-

A = p (1+r/100)n


where

a = amount on deposit at the end of the nth year
p = the original amount invested
r = the annual interest rate
n = number of years
 
Last edited:
Not touched javascript for years, but would adding var infront of the prompts work?

var money=prompt.....
var interest=prompt...

etc
 
nope ... :( ... im new to javascript... only started properly yesterday, lol, you dont need the "var" in front of them, but thanks in necase
 
I'll take a look when I get home if no one can help. I've got sh*tload of notes and stuff, so I'll take a look at them and see what you'd need to do
 
Glad ya got it sorted :) Usually find most errors are due to simple things being in the wrong place, can take hours or days sometimes to see it
 
Ok another problem....

... in the code... I have variables called "money" , "interest" and "payments" ... these hold the value the user inputs in. After the javascript ends... I need a table holding the information they input, how do I actually extract the value of whats in that variable into a table cell?
 


Top