CIT 597 Quiz 2: Forms and Basic JavaScript
Fall 2008, David Matuszek Name_________________________________________
  1. (10 points) In X/HTML forms, how do you indicate that two or more radio buttons belong to the same group?

    Give them the same name.

  2. (10 points) In X/HTML, clicking the text next to a radio button does not click the radio button. How do you correct this?

    Enclose the text and the radio button in a label.

  3. (30 points) What are the three places that JavaScript code can be put?

    In an external file
    In the head of the document
    As the value of an attribute in a tag



  4. (20 points) In JavaScript, the scope of a variable is determined by both where you declare it, and how you declare it.
    1. Tell all the ways that you could declare a variable so that it has global scope.

      Declare it with a var outside any function
      Just start using it, without declaring it


    2. Tell all the ways you can declare a variable so that it has local scope.

      Declare it with a var inside a function


  5. (10 points) Write JavaScript to create an object auto with a field type whose value is "Prius" and a year field whose value is 2005.

    auto = { type: "Prius", year: 2005 }    // semicolons at end of statements are optional

  6. (10 points) Write JavaScript to print out (using the document.write() method) all the information about the object auto. Do not assume it has only the two fields defined in the previous question.

    for (prop in auto) {
        document.write(prop + ":" + auto[prop]);
    }

  7. (10 points) What is the difference between the two operators == and ===? (Be sure to tell which is which.)

    === returns false if the two operands are of different types, but == tries to convert them to the same type before doing the comparison