/    Sign up×
Community /Pin to ProfileBookmark

Do While Loop?

I have a question for my Javascript class that i need help with

This is what I need to do

“Create an application that allows a Customer to enter an initial deposit (for example $1000), an annual interest rate (say 12%, which is 1% per month) and a target savings amount (say $2000). Each month they contribute an extra $10 to their account. Determine how many months it will take for the customer to reach this target amount. “

I have done this but its not quite working could someone please help

[CODE]<script type=”text/Javascript”>
function calc(){
intDep = document.form1.txtDep.value
intInt = document.form1.txtInt.value
intTar = document.form1.txtTar.value
intCont = document.form1.txtCont.value
intpermonth= (intInt / 12)
intActual = (intpermonth / 100)
intCount = 0
intBanked = intDep

do {intBanked = (intBanked + intCont + (intBanked * intActual));
intCount++;}

while ((intBanked + intDep) < intTar);

document.form1.txtMonths.value = intCount
}
</script>
</head>

<body>
<form name=”form1″>
Enter your deposit <input type=”text” name=”txtDep” /><br />
Enter your Interest rate <input type=”text” name=”txtInt” /><br />
Enter your Target savings <input type=”text” name=”txtTar” /><br />
Your required monthly contibution is <input type=”text” name=”txtCont” readonly=”readonly” value=”10″ /><br />
<br />
<input type=”button” name=”go” value=”calculate” onclick=”calc()” />
<br />
It will take <input type=”text” name=”txtMonths” readonly=”readonly” /> months to reach your target
</form>
</body>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@wbportMay 25.2011 — Your variables started as text fields (strings) in the form and they kept that attribute. Check out [B]Number()[/B], [B]parseInt()[/B], and [B]parseFloat()[/B] for moving your text fields to your variables.

HTH
Copy linkTweet thisAlerts:
@Pete1980authorMay 25.2011 — Ahhh, thank you soooo much, I completely forgot about that

and now I have it working

again, thanks
×

Success!

Help @Pete1980 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...