22C:005 Problem Solving and Computing - Spring 2000

Project 9 - Sorting Numbers with JavaScript

Due: May 5 for everyone!


Purpose: Sort ten numbers using JavaScript


Sorting Ten (10) Numbers using JavaScript

In this part of the assignment, you are to create a web page that sorts ten numbers entered by a user.    The user initiates the sorting by clicking on a button labeled "Sort in Ascending Order".   Your program will need to use JavaScript to sort the ten once the user clicks on one of the buttons.   The sorted numbers will then be placed into a set of output boxes.

We have included a screen shot of a web page that illustrates what we expect your completed page should look like.   Feel free to adapt the design to your liking, but the basic elements should still be there.

Screen capture of Working Program

For this assignment, we expect you to write code to sort the numbers in a JavaScript Array (see the "Things you will need to know" for more info on Arrays) using either Bubble Sort or Selection Sort.  To do this, you will need to write two functions:

  1. function swap_numbers( i, j )
    1. This function will take two parameters that refer to the two boxes you want to swap.
  2. function sort_numbers()
    1. This function will actually perform the sort.  This is where you will need to place your JavaScript code to implement either Bubble Sort, or Selection Sort.
Once you know that you've completely sorted the numbers, we want you to pop-up a confirmation window stating "Numbers have been sorted, click OK to view results."   Once the user clicks "OK", the sorted numbers will be placed into the output text boxes.

In summary, here's what you need to do for this portion of the assignment:

  1. Create a new web page (lab9_sort.html) and title it "Lab 9 - Sorting Numbers with JavaScript"
  2. Make a link from your home page (i.e. table of contents page) to your lab 9 page.
  3. Write JavaScript code that will sort the numbers entered by the user once the user clicks the sort button.  Your JavaScript code will consist of the following:
  4. Write JavaScript code to pop-up a confirmation dialog window informing the user that the numbers have been sorted.
Things you will need to know:

What you need to turn in

  1. Send your TA an e-mail message when you have completed your web pages.  The subject should be "Lab 9".  Please include the URL of your home page. Make sure you have a link on your home page to this assignment.
  2. Place a printed copy of your HTML code in either your TA's mailbox in 14 MLH, or under the office door of 101A MLH by the due date.   No credit will be given with out a paper copy of your code.