1 Replies - 1211 Views - Last Post: 11 June 2008 - 06:18 PM

#1 phak588   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-June 08

Summing from arrays based on data values

Post icon  Posted 11 June 2008 - 05:21 PM

var readerNameArray = ['ly-44', 'mr-7', 'rs-14', 'al-15', 'pn-44', 'wk-46'];
var statusArray = ['s', 's', 'rs-14', 'rs-14', 's', 's', 's', 'ly-44', 's', 's', 's', 'rs-14', 'ly-44', 's', 's', 'rs-14', 'mr-7','s', 's', 's', 's'];
var dueArray = ['s', 's', 345, 137, 's', 's', 's', 181, 's', 's', 's', 131, 284, 's', 's', 56, 315,'s', 's', 's'];
var replacementCostArray = [10.99, 3.87, 5.99, 11.99, 15.45, 3.99, 250.0, 58.70, 4.99, 9.99, 7.99, 7.99, 12.50, 75.0, 3.45, 15.0, 12.99, 5.50, 7.99, 6.99];

I have the functions to calculate a books cost etc

Question: Given a user from the readerNameArray how is it possible to sum up calculated values from the arrays based on a book due date and cost.

My function looks like this however it does not work.

function showFines()
{
var DaysOverDue = 0;
var FineCost = 0;
var TotalFineCost = 0;
var ReaderName = 'test';

document.write('<BR>'+ '=========================');
document.write('<BR>' + 'Administrator interfaces - Showing fines' + '<BR>');

for (i = 0; i < readerNameArray.length; i = i + 1) // Loop over the readers array
{
ReaderName = readerNameArray[i];
for (var count = 0; count < bookArray.length; count = count + 1)
{
DateDue = dueArray[count]; // Get the Date as an integer the book is due.
OnLoan = statusArray[count]; // Get the 's or readerID for the given book
DaysOverDue = daysOverdue(DateDue);

if (OnLoan == ReaderName && DaysOverDue >= 1)
// I think this is the problem !!
{
FineCost = LevyFine(count, DaysOverDue);
TotalFineCost = TotalFineCost + FineCost
document.write('<BR>' + '4th Reader ' + ReaderName + ' is fined ' + Total FineCost);
}
}
}

Hope someone can help being trying to find a solution for over 4 hours now....
Regards

Is This A Good Question/Topic? 0
  • +

Replies To: Summing from arrays based on data values

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1513
  • View blog
  • Posts: 8,295
  • Joined: 07-September 06

Re: Summing from arrays based on data values

Posted 11 June 2008 - 06:18 PM

This looks a lot like the same code (and project) as in this topic:
http://www.dreaminco...wtopic54460.htm

Also, please in the future post your code in these tags:
[code ] CODE GOES HERE [ /code] Without the spaces

Additionally, I see at least one problem with your code, you are calling to a function LevyFines() that doesn't exist in what you have provided, so if you would like help we will be needing the rest of the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1