

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Spring 2007
Due: Mon. Feb 26 at 4:00 pm For this assignment you will create a web page with an embedded JavaScript program. You will store this program as an HTML file in your UNC web space, and you will give it an 8-character or more filename that only you know. Then we can retrieve, run, and grade it by pointing our browser www.unc.edu/~ yourOnyen/yourSecretName.html but no one else can see it.
Use a simple text editor to create this program. Do not use Web generation tools. You may use the Lint tool, or other syntax checkers, to help you debug your JavaScript. HTML page structure Your script should be written as a function in the head section of an HTML page. That HTML page will serve as documentation for the program… it will explain what the program will do, what inputs are expected from the user (what are legal input values) and what information the user can expect to be computed, or what activities he/she can perform. Also explain how to make the program terminate. Somewhere on your HTML page will be a button that says something like “Click here to run the program”. When clicked, that button will execute your function/script. Input/Output In this program, user input will be obtained using the “prompt” and “confirm” statements. Output will be reported to the user via the “alert” statements initially, and then at the end some information will be reported with “document.write” statements. Functionality Your program will create an array… initially make it size 10. The user will be asked to input 10 words (using prompts). The words the user inputs will get stored in your array. After the array is loaded with the user’s input, the program will begin a section where the user will be asked to input a word, and the program will check to see if that word is in the array or not. An alert box will be popped up saying whether the word was in the array already or not, and if found, it will report what array location the word is in. This section of code is obviously a loop, so you need a way to get out of the loop. Therefore, have in this loop (either beginning or end, I don’t care) a “confirm” statement asking if the user would like to look up a word (or quit). Keep a second array, the same length as the array of words (10). Initially, load this array with all 0’s (zeros). This second array will be a collection of counters corresponding to the array of words. The counters will count how many times a word was looked up (meaning found). So when a word is looked up, if it is found you need to increment the
corresponding counter. For example, let’s call our word array “dictionary” and lets call the counter array “hits”. Let’s say dictionary[6] is the word “pecuniary”. If the user asks to find “pecuniary”, then I will find it in location 6 and I will increment hits[6] by one. At any point id I examine the value stored in hits[6] I will know how many times a user has asked to find that word. Now, when the user is done asking to have words looked up, the program will compute some simple information and produce a simple report on the HTML page (using document.write). Create a report that prints out each word in the array of words, shows its location in the array (was it element 0, 1, 2, etc) and also shows how many times it was looked up. Also compute the average number of times a word was looked up and report that… then you are done. One nice way to report this information is to generate an HTML