/    Sign up×
Community /Pin to ProfileBookmark

Help with my JS code???

I started learning Javascript recently and I have to create a mortgage calculator using Javascript. Here is my code, I know it’s probably very noobish but I need help with it and any help is greatly appreciated, thanks! ?

[code]

<html>
<head>
<script type=”text/javascript”>

function checkForZero (field) {
if (field.value == 0 || field.value.length == 0)
{ alert (“NO ZERO’S!!!”);
field.focus(); }
else
calculatePayment (field.form);
}

function show_prompt ()
{
var interestRate=prompt (“Enter interest Rate (&#37;)”);

var lengthLoan=prompt (“Enter length of the loan (Years)”);

var loanAmount=prompt (“Enter amount of loan($)”);

var n = interestRate/12*lengthLoan;

var m1 = loanAmount * math.pow ((1+interestRate) , n);

var m2 = m1 * interestRate;

var m3 = math.pow((1+interestRate) , n)-1;

var m = m2 / m3;

var mortgage=prompt (m);

}

</script>
</head>
<body>

<input type=”button” onclick=”show_prompt()” value=”Calculate” />

</body>
</html>
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 13.2011 — the prompt() method return always a String, not a Number, thus before a Math add or subtract you must transform it into a number.
<i>
</i>var interestRate=Number(prompt ("Enter interest Rate (&amp;#37;)"));
var lengthLoan=Number(prompt ("Enter length of the loan (Years)"));
var loanAmount=Number(prompt ("Enter amount of loan($)"));


And you should probably want to display the result, but you did not tell us which the result and where do you want it to be displayed.
×

Success!

Help @Aotz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...