View Full Version : help with school assignment

12-01-2009, 11:42 PM
hey all, i've been failing in my attempt to grasp JS. this is my last assignment..any help would be greatly appreciated...

Write a program that will ask the user to enter ten items (names of people, numbers,
addresses, or whatever). Use a prompt box to get the userís input. Youíll need to put it
in a loop of some sort.
After youíve gotten all ten items, sort them. You can use whatever sorting method you
prefer (Iíd suggest the bubble sort). Display the items in order, using either alert boxes or
document.write statements.
You can use the html framework on the next page for your program if you want.
Extra credit:
After displaying the items, ask the user to enter an item to search for. Use the binary
search (NOT the serial search!) to find the item in the list and display the itemís location
in the list. For example if the item was the first in the list, say that it was item # 1, the
second item is item # 2, etcetera. Remember, we want to tell the user which place the
item is in, not which element it is! Donít tell the user that it is item # 0 if it is the first
one in the list. The user wonít understand that weíre indexing from zero.

Old Pedant
12-02-2009, 12:21 AM
Read this:

Read especially rule 1.5

Now, *IF* you do the bulk of the work and get to the point where there is just one (or maybe two) thing(s) not working, *then* post the code here and likely somebody will help you.

12-02-2009, 01:39 AM
I like the extra credit part the best.

Old Pedant
12-02-2009, 02:29 AM
Ehhh... What's the point of doing a binary search in a list that's only 10 elements long??? Foolish waste of time.

And use a bubble sort??? Why, when you can use JS's builtin sort capabilities?

I know, I know. It's all a learning experience. Okay, fine. So why not make it "real world" in the process??