DerekAcorah
06-10-2007, 04:33 PM
Hello everyone,
I am having a problem implamenting an array code into a program. I have a program that lets you input 5 things, but for each time a user inputs information, i want it to tell me the day of the week, from Monday - Friday. I have got the code so it it does it on a day 1 to day 5 basis, and ive made an attempt at the Monday to Friday bit, but i can't get it going. What i have done so far is below, can anyone tell me where i have gone wrong ( I don't want the answer because id like to work it out for myself, but some hints as to what i have got to do would be nice!)
Thanks :)
<HTML>
<HEAD>
<TITLE> Number of library books borrowed
</TITLE>
<SCRIPT >
/* Program to read in a known number of data items and store them in an array */
var booksArray = new Array (5);
var dayNamesArray = ['Monday','Tuesday','Wednesday','Thursday','Friday'];
document.write('Array program to read in a known number of data items');
for (var Day = 0; Day < booksArray.length; day = day + 1)
{
dayNamesArray[day] = window.prompt('Enter number of books borrowed on ' + (day + 1),'')
};
document.write('<BR>' + '<BR>');
document.write('Confirmation of number of books borrowed' + '<BR>' + '<BR>');
for (var day = 0; day < booksArray.length; day = day + 1)
{
document.write(dayNamesArray[day] + '<BR>')
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
I am having a problem implamenting an array code into a program. I have a program that lets you input 5 things, but for each time a user inputs information, i want it to tell me the day of the week, from Monday - Friday. I have got the code so it it does it on a day 1 to day 5 basis, and ive made an attempt at the Monday to Friday bit, but i can't get it going. What i have done so far is below, can anyone tell me where i have gone wrong ( I don't want the answer because id like to work it out for myself, but some hints as to what i have got to do would be nice!)
Thanks :)
<HTML>
<HEAD>
<TITLE> Number of library books borrowed
</TITLE>
<SCRIPT >
/* Program to read in a known number of data items and store them in an array */
var booksArray = new Array (5);
var dayNamesArray = ['Monday','Tuesday','Wednesday','Thursday','Friday'];
document.write('Array program to read in a known number of data items');
for (var Day = 0; Day < booksArray.length; day = day + 1)
{
dayNamesArray[day] = window.prompt('Enter number of books borrowed on ' + (day + 1),'')
};
document.write('<BR>' + '<BR>');
document.write('Confirmation of number of books borrowed' + '<BR>' + '<BR>');
for (var day = 0; day < booksArray.length; day = day + 1)
{
document.write(dayNamesArray[day] + '<BR>')
}
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>