bigsquid

06-11-2007, 03:19 PM

hi,

i have written the following code however it doesn't function as intended. the final for loop needs to report the greatest number in the array aswell as the day it occured. i am a complete novice but i am guessing the numbers need to be converted to carry out the necessary arithmetic. any help would be greatly appreciated. i'm sure it very simple but i am struggling to work it out.

cheers

thebigsquid

<HTML>

<HEAD>

<TITLE> books borrowed

</TITLE>

<SCRIPT >

/* Program to read in a known number of data items and store them in an array */

var booksBorrowed = new Array (5);

var dayNamesArray = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];

var maxNumberBooks;

document.write('Array program to read in a known number of data items');

for (var day = 0; day < booksBorrowed.length; day = day + 1)

{

booksBorrowed[day] = window.prompt('Enter number of books borrowed on ' + dayNamesArray[day],'')

};

document.write('<BR>' + '<BR>');

document.write('Confirmation of data input' + '<BR>' + '<BR>');

for (var day = 0; day < booksBorrowed.length; day = day + 1)

{

document.write('the amount of books borrowed on ' + dayNamesArray[day] + ' is ' + booksBorrowed[day] + '<BR>')

};

maxNumberBooks = 0

for (var day = 0; day < booksBorrowed.length; day = day + 1)

{

if (booksBorrowed[day] > booksBorrowed[maxNumberBooks])

{

maxNumberBooks = day

}

};

document.write('the greatest number of books borrowed was ' + booksBorrowed[maxNumberBooks] + ' on ' + dayNamesArray[maxNumberBooks])

</SCRIPT>

</HEAD>

<BODY>

</BODY>

</HTML>

i have written the following code however it doesn't function as intended. the final for loop needs to report the greatest number in the array aswell as the day it occured. i am a complete novice but i am guessing the numbers need to be converted to carry out the necessary arithmetic. any help would be greatly appreciated. i'm sure it very simple but i am struggling to work it out.

cheers

thebigsquid

<HTML>

<HEAD>

<TITLE> books borrowed

</TITLE>

<SCRIPT >

/* Program to read in a known number of data items and store them in an array */

var booksBorrowed = new Array (5);

var dayNamesArray = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];

var maxNumberBooks;

document.write('Array program to read in a known number of data items');

for (var day = 0; day < booksBorrowed.length; day = day + 1)

{

booksBorrowed[day] = window.prompt('Enter number of books borrowed on ' + dayNamesArray[day],'')

};

document.write('<BR>' + '<BR>');

document.write('Confirmation of data input' + '<BR>' + '<BR>');

for (var day = 0; day < booksBorrowed.length; day = day + 1)

{

document.write('the amount of books borrowed on ' + dayNamesArray[day] + ' is ' + booksBorrowed[day] + '<BR>')

};

maxNumberBooks = 0

for (var day = 0; day < booksBorrowed.length; day = day + 1)

{

if (booksBorrowed[day] > booksBorrowed[maxNumberBooks])

{

maxNumberBooks = day

}

};

document.write('the greatest number of books borrowed was ' + booksBorrowed[maxNumberBooks] + ' on ' + dayNamesArray[maxNumberBooks])

</SCRIPT>

</HEAD>

<BODY>

</BODY>

</HTML>