Welcome to Dream.In.Code
Getting Help is Easy!

Join 119,780 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,393 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



searching through and editing an array

 
Closed TopicStart new topic

searching through and editing an array

cavvysri
post 21 Jun, 2008 - 06:18 AM
Post #1


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


Hi,

im trying to write code for someone to reserve a book, the books are stored in an array, and there are other arrays to show which books have been reserved or not..

the user will enter the index number of a book to reserve, the program then searches through the array and then reserves the book by editing the array so the book is no longer available.

im struggling with the code, can anyone give any pointers please?

CODE


var borrowedArray = ['-', '-', '-', 'rs-14', '-', '-'];
var reservedArray = ['-', 'ly-44', '-', '-', '-', '-'];
var readerNameArray = ['ly-44', 'mr-7', 'rs-14', 'al-15', 'pn-44', 'wk-46'];
var indexArray = ['0', '1', '2', '3', '4', '5'];

document.write('' + '<BR>' + 'What would you like to do?' + '<BR>')
                        document.write('1. Reserve a book' + '<BR>')
                        document.write('2. Borrow a book' + '<BR>')
                        readerIndex= window.prompt('Enter 1 or 2 to select','');
                        if (readerIndex == 1)
                            document.write('please enter the index number of the book you wish to reserve' + '<BR>')
                            readerIndex = 0;
                            readerIndex = window.prompt('Enter a number 0 - 6 to select','');
                            
                            
                            if (readerIndex > 6)
                            {
                                document.write('No such book!')
                            }
                            if (readerIndex[bookStatus] == 'reserved' || 'on loan')
                            {
                                document.write('you cannot reserve that book')
                            }
                            else
                            {
                                document.write('Book reserved')
                            }



i know this is completely wrong, as i think i need to use a for loop to loop through the array,
can anyone give an example of how to edit an array?
User is offlineProfile CardPM

Go to the top of the page

Closed TopicStart new topic
Time is now: 10/15/08 09:37PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month