View Full Version : help please
vbean
03-25-2009, 11:08 PM
can someone pleeeease help me with this javascript
i have no idea what's wrong with it
but i can load it up so there must be something wrong with it...
<HTML>
</HEAD>
<TITLE> Last HOMEWORK </TITLE>
<SCRIPT type="text/javascript">
function monthlyRate (interest) {
var rate = interest / 100;
rate = rate + 1;
rate = ((1 + interest) ^(1/12)) minus 1);
return monthRate;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
var price = parseFloat (prompt ( "What was the purchase price for the item you are interested in buying?"));
var interest = parseFloat ( prompt ( "What is the annual interest rate on your credit card?"));
var pay = parseFloat ( prompt ("How much do you plan to pay towards you credit card balance each month?"));
var monthly = monthlyRate (interest);
var bill = price;
var month = 0;
while (bill >= pay) {
bill = price - pay
bill = bill * (1 + monthRate)
price = bill
}
if ( bill < pay) {
var amount = pay * month + bill
alert ("You have actually spend "+ amount +" on this item")
}
</BODY>
</SCRIPT>
</HTML>
The operator '^' doesn't work in js.
Use Math.sqrt().
More info here (http://www.javascripter.net/faq/mathfunc.htm).
vbean
03-26-2009, 12:05 AM
still doesn't work :(
thanks though
Here:
return monthRate;
Shouldn't it be:
return rate;
Still using the Math.sqrt.
vbean
03-26-2009, 12:32 AM
ok. did that as well and still nothing. i used firebug and it said :
missing ) in parenthetical
[Break on this error] rate = (((1 + interest) Math.sqrt(1/12)) minus 1));\n
javascri... 8.html (line 12)
syntax error
[Break on this error] </BODY>\n
i have no idea what this means. :(
I think it should be:
rate = (((1 + interest) Math.sqrt(1/12)) - 1);
But I made a mistake, use Math.pow(a,b). See more info on the page above.
vbean
03-26-2009, 12:49 AM
oh yes! you have a good eye :)
but firebug still says the same thing...
thanks for helping me btw
Glad to help you so far, I hope you saw my edit about Math.pow.
Please gimme all your code with the updated stuff.
vbean
03-26-2009, 12:54 AM
<HTML>
<HEAD>
<TITLE> Last HOMEWORK </TITLE>
<SCRIPT type="text/javascript">
function monthlyRate (interest) {
var rate = interest / 100;
rate = rate + 1;
rate = (((1 + interest) Math.pow(1,12)) - 1));
return Rate;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
var price = parseFloat (prompt ( "What was the purchase price for the item you are interested in buying?"));
var interest = parseFloat ( prompt ( "What is the annual interest rate on your credit card?"));
var pay = parseFloat ( prompt ("How much do you plan to pay towards you credit card balance each month?"));
var monthly = monthlyRate (interest);
var bill = price;
var month = 0;
while (bill >= pay) {
bill = price - pay
bill = bill * (1 + monthRate)
price = bill
}
if ( bill < pay) {
var amount = pay * month + bill
alert ("You have actually spend "+ amount +" on this item")
}
</BODY>
</SCRIPT>
</HTML>
Well, I didn't spend time orgainizing it, but here:
<HTML>
<HEAD>
<TITLE> Last HOMEWORK </TITLE>
<SCRIPT type="text/javascript">
function monthlyRate(interest) {
var rate = interest / 100;
rate = rate + 1;
rate = (((1 + interest) + Math.pow(1, 12)) - 1);
return rate;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT type="text/javascript">
var price = parseFloat(prompt("What was the purchase price for the item you are interested in buying?"));
var interest = parseFloat(prompt("What is the annual interest rate on your credit card?"));
var pay = parseFloat(prompt("How much do you plan to pay towards you credit card balance each month?"));
var monthly = monthlyRate(interest);
var bill = price;
var month = 0;
while (bill >= pay) {
bill = price - pay
bill = bill * (1 + monthly)
price = bill
}
if (bill < pay) {
var amount = pay * month + bill
alert("You have actually spend " + amount + " on this item")
}
</SCRIPT>
</BODY>
</HTML>
vbean
03-26-2009, 01:17 AM
wow how did you do that!?
im a beginner so i don't know much.
umm i uploaded it and clicked on "debug script" and it gave me a lot of text i don't understand a which is clickable... what should I do next?
I took out the extra ')' that was not needed. I added a + before the power, and corrected the variable names. ;)
Take a screen shot of the error please.
vbean
03-26-2009, 01:33 AM
haha sounds so simple
Does it give you a error? Like does it say: Error {1}
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.