JavaScript Programming Basics
Kalamazoo College


due in class on Monday of Sixth Week

Review Of: Chapter 5 (JavaScript Programming), Mini-Labs 1, 2, 3 and 4, and Labs 3 and 4.

You may work individually or in groups of 2 people to finish this project. You may utilize anyone you find reliable to answer questions and help debug your program, but your group should attempt the programming on your own before seeking help.

Check out the page on programming tips to help you. Also, the page Grading Criteria to see the breakdown of the points given for this project. Turn in the URL (location) of your Expert Advice System on the due date. For example, you may have the URL be where k97ab01 is your username (email id) on henson.

Expert Advice System Enhancements

For this project you will modify your expert advice system from Lab #4. You will mostly be changing the algorithm behind the page, not the user interface.
  1. Define a function to create an array consisting of the questions that you wish to ask. Leave array element 0 blank, and number the remaining questions as you did in Lab #4 (so question #1 is stored in the array element with index 1, question #2 is in array element 2, etc.). You can do this with a makeQArray function like our make CD array function in Mini-Lab #4.
         function makeQArray()
              this.length=16;                // 15 questions + blank element
              this[1]="Do you want to go out?";

  2. Define a function to create a second array of the answers that you will give. The answer array will begin with the left-most answer from your decision tree in element 0. The function to make the answer array will be similar to the one above.

  3. Create three global variables (variables that are created above any functions but within the SCRIPT tags). The first will be the same question number variable you had in Lab 4. The second will be the commands needed to make the two arrays. For example, var questions = new makeQarray(); creates the question array.

  4. You will still need the startOver function, but now it will display the question from the array instead of from a hard-coded string. This function should set the question number to 1, display the first question (questions[1]) to the question text field and clear the history and answer text areas.

  5. Now modify the askTheExpert function. This function should add to the history field as it did before. Next the function must decide what to display based on the answer given and the question number. You will no longer do this with all of the if statements from Lab #4, so delete those from the function. Instead, the function will contain just two if statements. The first will change the question number variable to contain the number of the next question. How do we know what the next question number should be? Notice from your decision tree that there is a very simple formula that describes the left child's question number for any given question in the tree. There is another formula, almost as simple, to compute the number of the right child for any question in the tree. The first if statement will determine which formula to use to calculate the next question number, and then will assign the new question number to the question number variable.

    The second if statement in askTheExpert will decide (based on the question number) whether a question or answer will be displayed, and then display the appropriate question or answer. The text of the question can be obtained by looking in the question array at index questNum. The text of the answer can be obtained by looking in the answer array, but you will have to adjust the questNum index (by subtracting an appropriate value) to get the right index into the answer array.

  6. Once the expert advice system is functioning properly, add graphics or text to the page to make it a better user interface. Add text to describe what to do, align the page and buttons in an easy-to-read format and add an appropriate background.

  7. Add comments to the code to describe what you are doing. For each function add comments to describe the function's purpose.