Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Return array of values ?

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-19-2013, 08:10 AM PM User | #1 billboy New Coder   Join Date: Feb 2013 Posts: 44 Thanks: 2 Thanked 0 Times in 0 Posts Return array of values ? I am using the following function to get information on loan payments I would like to pass through about 7 different accounts and then total the interest paid for all or however many I need I am really a bit lost when it comes to arrays and quite frankly need even sure if that is what I want to do, I think it is. Any help or insight would be appreciated Thanks Code: ```function myPaymentCalc(interestRate,monthlyPayment,principal) { accumulatingInterest = 1; if (! validInt(interestRate) || ! validInt(monthlyPayment) || ! validInt(principal)) return(false); if (interestRate == 0 || monthlyPayment == 0 || principal == 0) { alert("You need to specify your monthly payment, credit card " + "interest rate and current debt amount before I can calculate " + "how long it'll take for you to pay off your debt."); return(false); } interestRate = (interestRate > 1)? interestRate / 100.0 : interestRate; monthlyInterestRate = interestRate / 12; if (principal * monthlyInterestRate > monthlyPayment) { monthlyrate = "\$" + centNotation(principal * monthlyInterestRate); permonthPayment = "\$" + centNotation(monthlyPayment); alert("You've got a fundamental problem: your monthly payment of " + permonthPayment + " is less than the interest added each month " + "(which is " + monthlyrate + ") and you will never " + "pay off this debt. It might be a good time to call your creditors."); return(false); } interimVal1 = monthlyPayment - (monthlyInterestRate * principal) numberOfPayments = (Math.log(monthlyPayment) - Math.log(interimVal1)) / Math.log(1+monthlyInterestRate); numberOfPayments = Math.ceil(numberOfPayments); interimVal2 = Math.pow((monthlyInterestRate+1), (numberOfPayments-1)); remaining = (principal * interimVal2) - (monthlyPayment/monthlyInterestRate) * (interimVal2 - 1); totalPayment = monthlyPayment *(numberOfPayments-1) + remaining; payments = numberOfPayments; totalpayment = formatNumber(totalPayment); interestPaid = formatNumber(totalPayment-principal);```
 02-19-2013, 01:08 PM PM User | #2 007julien Regular Coder   Join Date: May 2012 Location: France Posts: 174 Thanks: 0 Thanked 27 Times in 25 Posts Simply return [payments,totalpayment,interestPaid]; ? But your monthlyInterestRate = interestRate / 12; is wrong. The monthlyInterestRate (in %) should verify : Math.pow(1+monthlyInterestRate/100,12) = 1+interestRate/100; Then it is given by Math.pow(1+interestRate/100,1/12) -1 which is a always little lower. You work as bankers ! Last edited by 007julien; 02-19-2013 at 01:19 PM..
02-19-2013, 07:00 PM   PM User | #3
billboy
New Coder

Join Date: Feb 2013
Posts: 44
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by 007julien Simply return [payments,totalpayment,interestPaid]; ? But your monthlyInterestRate = interestRate / 12; is wrong. The monthlyInterestRate (in %) should verify : Math.pow(1+monthlyInterestRate/100,12) = 1+interestRate/100; Then it is given by Math.pow(1+interestRate/100,1/12) -1 which is a always little lower. You work as bankers !
Thanks I will look into that, but I doesnt address the question in my post

 02-19-2013, 07:55 PM PM User | #4 Philip M Supreme Master coder!     Join Date: Jun 2002 Location: London, England Posts: 17,476 Thanks: 200 Thanked 2,470 Times in 2,448 Posts I don't see any array in your code. But you declare an array with var myarray = [], and then you can store values in each array index (remember the array index starts at 0) , and ultimately total them using a loop. Remember that alerts are regarded as obsolete and should only be used for testing. Use DOM methods to display a message to your users. __________________ All the code given in this post has been tested and is intended to address the question asked. Unless stated otherwise it is not just a demonstration.
02-19-2013, 07:58 PM   PM User | #5
billboy
New Coder

Join Date: Feb 2013
Posts: 44
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by Philip M I don't see any array in your code. But you declare an array with var myarray = [], and then you can store values in each array index (remember the array index starts at 0) , and ultimately total them using a loop. Remember that alerts are regarded as obsolete and should only be used for testing. Use DOM methods to display a message to your users.
Yes I know there isnt an array

Quote:
 I am really a bit lost when it comes to arrays and quite frankly need even sure if that is what I want to do, I think it is. Any help or insight would be appreciated
That function takes one set of variables I would like to use it to pass several and store the result of each interest calculation then add them together and have the answer displayed on my document

 02-19-2013, 11:42 PM PM User | #6 007julien Regular Coder   Join Date: May 2012 Location: France Posts: 174 Thanks: 0 Thanked 27 Times in 25 Posts Yes. We are of the same opinion... I give the response without question ! See for example the Peter-Paul Koch's function findPosition which return two value with an Array. An other way to return an Array consist to use the slide method (return myArray.slide(0)) which return a copy of an array... Last edited by 007julien; 02-19-2013 at 11:46 PM..
02-20-2013, 12:37 AM   PM User | #7
jmrker
Senior Coder

Join Date: Aug 2006
Location: FL
Posts: 2,935
Thanks: 36
Thanked 477 Times in 471 Posts

Quote:
 Originally Posted by 007julien Yes. We are of the same opinion... I give the response without question ! See for example the Peter-Paul Koch's function findPosition which return two value with an Array. An other way to return an Array consist to use the slide method (return myArray.slide(0)) which return a copy of an array...
I assume you mean slice function

 02-20-2013, 01:00 AM PM User | #8 007julien Regular Coder   Join Date: May 2012 Location: France Posts: 174 Thanks: 0 Thanked 27 Times in 25 Posts Yes Obviously I do ! Thanks
02-20-2013, 09:19 AM   PM User | #9
Philip M
Supreme Master coder!

Join Date: Jun 2002
Location: London, England
Posts: 17,476
Thanks: 200
Thanked 2,470 Times in 2,448 Posts
Quote:
 Originally Posted by billboy Yes I know there isnt an array That function takes one set of variables I would like to use it to pass several and store the result of each interest calculation then add them together and have the answer displayed on my document
You do realise that you cannot store values in this way to use in some other session? In other words, you would have to run your script several times in a loop, adding the calculated values to the array each time, and finally totalling them. But without cookies or local storage (or of course a server-side database) the contents of the array are lost when the program ends.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 10:33 AM.