Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with school assignment

    hey all, i've been failing in my attempt to grasp JS. this is my last assignment..any help would be greatly appreciated...

    Exercise:
    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.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Read this:
    http://www.codingforums.com/rules.htm

    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    726
    Thanks
    35
    Thanked 132 Times in 123 Posts
    I like the extra credit part the best.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    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??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •