CSC 112 JavaScript Test #1 Spring 2006

Name:______________________________________  Monday February 13, 2006
Print this exam and write your answers on the printed copy or type your answers on the document and print. Turn in the hard copy.

  1. (40 pts.) Write code for each of the following:
    1. Create a form named "codelab".
       
    2. Add text input named "input".
       
    3. Add a textarea named "feedback".
       
    4. Add an object or event handler so the function "analyze" is called (this function -to be written- takes information from the input and generates feedback.)
       
  2. (30 pts.) Write an entire function definition named "analyze" that
    1. Checks to see if the input is empty and alerts the user to enter input if so.
       
    2. Checks to see whether the input is more than 10 characters, then places "Long winded today?" in the feedback.
       
    3. If the test condition in b. is false, place "concisely stated" in the feedback.
       
  3. (30 pts.) The script in the head declares an array named "ansKey" as follows:
    var ansKey = new array();
    ansKey[0] = "b"; ansKey[1] = "c"; ansKey[2] = "a"; 
    1. What is value of guess (exactly) after the following loop?
      var guess = "";
      for (i=1;i<ansKey.length;i++){
        guess += ansKey[i] + (i%2==0? ".":", ");
      }
       
    2. In the body of an HTML document, a form named "test" has three radio buttons for each of three questions (nine radio buttons total). The first three radio buttons are named "q0", the next three "q1", and finally the last three "q2". The value for each button corresponds to the displayed question and the id for each button is "a", "b", and "c" respectively for each question.
      Write a function
      that gets the form and button name (or part of it) and checks the selected answer for each question against the ansKey value for each question. When completed the function should call an alert window that displays the number correct out of three.