473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to add all values of a specific variable using do-while and Javascript?

7
Hi.

I need help. I am using javascript to come up with a loan's amortization schedule. Everything is already in place except for adding up the values of a certain field that is generated by a do-while loop (in this case all the interest payments so i can come up with a TOTAL INTEREST PAID).. i have been playing around with the code for a couple of hours but i seem to hit a brick wall...

Thank you very much...

My part of my code is pasted below:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. <!-- var mlibor=document.calculator1.mlibor.value
  4. var loan=document.calculator1.loan.value
  5. var margin=document.calculator1.margin.value
  6. var mincome=document.calculator1.mincome.value
  7. var mortgage1=document.calculator1.mortgage1.value
  8. var mortgage2=document.calculator1.mortgage2.value
  9. var mortgage3=document.calculator1.mortgage3.value
  10. var livingexpenses=document.calculator1.livingexpenses.value
  11. var miscexpenses=document.calculator1.miscexpenses.value
  12. var totalmapaccount=document.calculator1.totalmapaccount.value
  13. var month=document.calculator1.month.value
  14. var day=document.calculator1.day.value 
  15. var year=document.calculator1.year.value 
  16.  
  17. var begbal_simpleinterest2 = (loan - mincome) + parseFloat(mortgage1) + parseFloat(mortgage2) + parseFloat(mortgage3) + parseFloat(livingexpenses) + parseFloat(miscexpenses)
  18. var int_minpayment2 = begbal_simpleinterest2 * (fir/1200)
  19.  
  20. var fir = parseFloat(mlibor) + parseFloat(margin)
  21. var loan1=r2(loan) 
  22.  
  23. var count = 0; 
  24. var month1=month-1;
  25. do { 
  26. count++; 
  27. month1++;
  28.  
  29. var newbalance = loan
  30. var begbal_simpleinterest = (loan - mincome) + parseFloat(mortgage1) + parseFloat(mortgage2) + parseFloat(mortgage3) + parseFloat(livingexpenses) + parseFloat(miscexpenses)
  31. var int_minpayment = begbal_simpleinterest * (fir/1200)
  32. var ending_bal = begbal_simpleinterest + parseFloat(int_minpayment)
  33. var avail_bal = totalmapaccount - ending_bal
  34.  
  35. var mincome1=r2(mincome)
  36. var mortgage11=r2(mortgage1)
  37. var mortgage22=r2(mortgage2)
  38. var mortgage33=r2(mortgage3)     
  39. var livingexpenses1=r2(livingexpenses)
  40. var miscexpenses1=r2(miscexpenses)
  41. var newbalance1=r2(newbalance)
  42. var begbal_simpleinterest1=r2(begbal_simpleinterest)
  43. var int_minpayment1=r2(int_minpayment)
  44. var ending_bal1=r2(ending_bal)
  45. var avail_bal1=r2(avail_bal)
  46.  
  47. var int_minpayment2 = int_minpayment + parseFloat(int_minpayment)
  48.  
  49. if (month1 >=13 ) { 
  50. month1 = month1 - 12 
  51. }
  52.  
  53. document.write ("<tr bgcolor=33CCFF>")
  54.  
  55. document.write ("<td><font color=003399 face=arial size=2><b>" + count + "</b></font></td>")
  56. document.write ("<td><font color=003399 face=arial size=2><b>" + month1 + "/" + day + "/" + year + "</b></font></td>")
  57.  
  58. document.write ("<td align=right><font color=000066 face=arial size=2>$ " + newbalance1 + "</font></td>" + "<td align=right><font color=000066 face=arial size=2>$ " + mincome1 + "</font></td>" )
  59.  
  60. document.write ("<td align=right><font color=000066 face=arial size=2>$ " + mortgage11 + "</font></td>" + "<td align=right><font color=000066 face=arial size=2>$ " + mortgage22 + "</font></td>" )
  61. document.write ("<td align=right><font color=000066 face=arial size=2>$ " + mortgage33 + "</font></td>" + "<td align=right><font color=000066 face=arial size=2>$ " + livingexpenses1 + "</font></td>" )
  62. document.write ("<td align=right><font color=000066 face=arial size=2>$ " + miscexpenses1 + "</font></td>" )
  63. document.write ("<td align=right><font color=000066 face=arial size=2>$ " + begbal_simpleinterest1 + "</font></td>" )
  64. document.write ("<td align=right><font color=red face=arial size=2>$ " + int_minpayment1 + "</font></td>" )
  65. document.write ("<td align=right><font color=000066 face=arial size=2>$ " + ending_bal1 + "</font></td>" )
  66. document.write ("<td align=right><font color=000066 face=arial size=2>$ " + avail_bal1 + "</font></td>" )
  67.  
  68. loan = ending_bal
  69.  
  70. }
  71. while 
  72. (ending_bal > 0) 
  73.  
  74. var newcount= count
  75. var numyear = newcount/12
  76. var numyear1=r2(numyear)
  77.  
  78. document.write ("</tr><tr align=center bgcolor=0066CC><td colspan=13><font face=arial size=3 color= white><b>Years to pay-off:" + numyear1 + "<br>Original Loan Amount: $" + loan1 +"<br>") 
  79. document.write ("Total Interest Paid: $" + sum+"</b></font></td>") 
  80. document.write ("</tr>") 
  81. document.write ("<tr><td colspan=13 bgcolor=0066CC height=25 align=center>")
  82.     document.write("<a href=javascript:history.back();><font color=CCFFFF size=1 face=arial>::Back::</font></a> <a href=javascript:window.close();><font color=CCFFFF size=1 face=arial>::Close::</font></a> <a href=index.html><font color=CCFFFF size=1>::Calculator Index::</font></a></td></tr></table>") 
  83.  
  84. }
  85. //-->
  86. </script>
  87.  
Apr 30 '07 #1
2 1353
iam_clint
1,208 Expert 1GB
what exactly do you need this todo? sorry I just don't get your question I guess.
Apr 30 '07 #2
shiloh
7
Hi. I'm sorry if my question sounded vague. This code line:

var int_minpayment2 = int_minpayment + parseFloat(int_minpayment)

does not add up all my int_minpayment (This is the minimum interest payment that is generated by the loop)

I need help in adding up all the values of int_minpayment to come up with the total interest paid.

I am pasting a hyperlink of the screen cap here and the column that is encircled in red will be the values that i need to add up.



Thanks again...
May 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jonathan | last post by:
Thanks for the help and commentary on sessions. I had another question or two on a related topic. I installed a newer version of php and went in to set it to read global variables, which was...
12
by: David Walker | last post by:
Hi I have a program which I need to interface with a webpage - the webpage will accept an input (probably a 'post' string from the program) and then will process it and needs to return a value. ...
8
by: deko | last post by:
Is there a rule of thumb for quoting variable values? For example, do I have to put all string number values in quotes? strAbc = "3" ? What about long, int and byte? I assume these are NOT...
17
by: MLH | last post by:
A97 Topic: If there is a way to preserve the values assigned to global variables when an untrapped runtime error occurs? I don't think there is, but I thought I'd ask. During development, I'm...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.