CogSci 3
Spring 04
Assignment 7 -- JavaScript -- Grading Criteria

There are different point scales used on each assignment. Harder assignments have more points possible.

Assignment 7 -- Javascript Web Page

  • 45 points -- plus 3 points extra credit plus 3 more points for cleverness, neatness, good variable names.

    Part 1 -- Basic File/Page
    8 Points

    1. 1 point for creation of the hw7 folder and for having a final page named javascript.html.
    2. 1 point <HTML> and </HTML> tags, <HEAD> and </HEAD> tags, and <BODY> and </BODY> tags
    3. 1 point for having Title tags
    4. 1 point for a H1 header
    5. 1 point a working <IMG SRC> tag
    6. 1 point for a working H6 citation for the image.
    7. 1 point for correctly <CENTER>ing
    8. 1 point for <HR> line and copyright

    Part 2 & 3 -- Changing background color with a <FORM>
    11 Points

    The background color should change when the button is clicked
    1. 1 point for the HTML comments:
      <!--  This is the START of Part 2 -->
      <!--  This is the END of Part 2 -->
      
    2. 2 points for creating the simple form and changing the VALUE="..." attribute of the BUTTON to something sensible.
      <FORM>
      <INPUT TYPE="BUTTON" VALUE="Change Color" onClick="java_change_color();">
      </FORM>
      
    3. 1 point for properly adding the onClick attribute to the BUTTON
    4. 1 point for a basic function definition and changing its name.
    5. 1 point for the global variable delcaration, and renaming the variable something other than (better than?) "bar"
    6. 1 point for the declaration of local variable "foo" and changing its name
    7. 1 point for assigning a different color (web safe?) to "foo"
    8. 1 point for a commented out alert()
    9. 2 points for a correct "if()".

      The finished function might look something like the following. (Note to graders, their function may have random number generation and a more complex "if()" if they tried the extra credit.)

      var original_color = document.bgColor;
      
      function java_change_color() {
              var color;
      
              color = "0xffcc33";
              // document.bgColor = color;
              // alert( "java_change_color called" );
      
              if (document.bgColor == original_color) {
                      document.bgColor = color;
              } else {
                      document.bgColor = original_color;
              }
      }
      

    Part 4a -- The Second Form
    7 Points

    7 points if the <FORM> parts show up on page, a text box, a button, and a second text box, plus are aligned, along with some explanatory text like the example.
    1. 1 point for putting in the HTML comments
      <!--  This is the START of Part 4 -->
      <!--  This is the END of Part 4 -->
      
    2. 1 point <FORM> and </FORM> tags
    3. 1 point for <INPUT> tag for first text box
    4. 1 point for <INPUT> tag for button
    5. 1 point for <INPUT> tag for second text box
    6. 1 point for <BR> or <P> to vertically space parts (or use a <TABLE>)
    7. 1 point for adding text per the sample to explain what the boxes and button are for.

    Part 4b & 4c -- More Form, and copyName function
    8 Points

    8 points if you can type into the <FORM> and click the button and have something show up in the Output box
    1. 1 points for putting NAME and VALUE attributes on <FORM> and both <INPUT=TEXT> tags
    2. 1 point for VALUE= on <BUTTON>
    3. 1 point for onClick="copyName();" attribute
    4. 1 point for function copyName() { } definition
    5. 3 points for correct body for the copyName() function definition that copies the value of the Input text box, concatenates it with a greeting string and then sticks the result into the Output text box. The body of copyName() should be:
          var Str;
          Str = "wuzup " + document.MyForm.Input.value;
          document.MyForm.Output.value = Str;
      

      The instructions are pretty explicit, so there will be -.5 point, if you did something like:
      document.MyForm.Output.value = "Hi" + document.MyForm.Input.value;
      
    6. 1 point if it actually works

    Part 7 -- Changing Image
    11 Points

    11 points if the Image (and citation) changes on Reload
      The finished JavaScript might look something like:
      
      var URL;
      var PixURLs = new Array(
      "http://www.photo.net/cr/maps/highways-4bit.gif",
      "http://www.photo.net/cr/sloth-iguana-58-sm.jpg",
      "http://www.photo.net/cr/corco-macaw-6-sm.jpg",
      "http://www.photo.net/cr/pj-shawn-46-sm.jpg",
      "http://www.photo.net/cr/coati-7.jpg",
      "http://icogsci1.ucsd.edu/~cg3xzz/costaricamap.gif"
      );
      var RanNum = new Date().getSeconds();
      
      RanNum = RanNum % 6;
      
      URL = PixURLs[RanNum];
      
      document.write( '<IMG SRC="' + URL + '">' );
      
      document.write( "<H6>" + URL + "</H6>");
      
      The scoring is something like:
    1. 1 point for the HTML comments:
      <!--  This is the START of Part 5 -->
      <!--  This is the END of Part 5 -->
      
    2. 1 point for commenting out (but leaving on the page) the original IMG SRC and citation.
    3. 1 points for the declaration of "boo" and changing its name
    4. 1 points for the declaration of the name of the random index.
    5. 1 point for PixURLs array declaration and URLs
    6. 1 points for assigning a "random" number per examples
      	var RanNum2 = new Date().getSeconds();
      	RanNum2 = RanNum2 % 6;
      	
    7. 1 point for setting "boo" to PixURLs[ random_number ].
    8. 1 point for the first document.write() which has the IMG SRC
    9. 1 point for the citation: document.write( URL ); (with their variable)
    10. 1 point for figuring out out to get the citation in H6 headers.
    11. 1 point if the images and citations actually change.

    Extra Credit

    3 Points

    3 points if you correctly added code to the "blah" function to generate a "random" number and then use if() else if () else to pick a background color based on it.
    1. 2 points for a properly generated random number between 0 and 5
    2. 1 points for a proper if() else if() statement that assigns a different color to the background based on the random number. Only .5 points if they have "an array" solution; the instructions ask for if().

    Extra Credit

    3 Points

    1. Up to 3 points can be awarded for neatness, really good variable or function names, or clever solutions.
    2. Use this sparingly.

    WML
    ©opyright 2001-2004 Mark R. Wallen
    Last updated: Thu Jun 10 22:45:19 2004