To Lecture Notes

IT 130 -- 2/15/10

 

Review Questions

  1. What is abstraction? How does it apply to JavaScript functions?

     
  2. List some reasons for using functions in JavaScript
     
  3. What is displayed? Watch out for trick problems. The * and / operators are always evaluated before + and -.
     
      // Prob 3a.
      var x = 1 + 2 * 12;
      document.frmA.txt1.value = Math.sqrt(x); 
      
      
      // Proj 3b.
      var x = 3.95 + 0.21;
      document.frmA.txt1.value = Math.floor(x);
      
      
      // Proj3c.
      var x = Math.random( );
      var y = 3 * Math.floor(x);
      var z = y + 2;
      document.frmA.txt1.value = z;
      
      
      // Prob 3d.
      var x = 1 - 2 * 12;
      var y = Math.ceil(x);
      y = document.frmA.txt1.value;
      
      
  4. Write JavaScript statements that place a random variable from the set {100, 101, 102, 103, 104, 105} in the textbox txtRandom. Use getElementById to access the textbox.

 

Dynamically Changing an Image

 

Practice Problems

  1. Write an HTML page with one image and two buttons. The buttons have the captions Head and Tail. When the head button is clicked, display the image silvereagle.jpg. When the tail button is clicked, display the image silvereagleback.jpg. Use two event handler functions showHead and showTail.
     
  2. Write an HTML web page with a textbox, a button and an image that initially displays blank.jpg. When a number from 1 to 6 is entered into the textbox and the button is clicked, the page should display the corresponding image of a dog with its owner:

 

Referencing a Control by ID

 

Practice Problems

  1. Convert Temperature 1 Example to access the textboxes by id.
     
  2. Rewrite the DogOwner Example in the Practice Problem 2 above so that is uses control ids instead of names.

 

The Dice Examples

 

Dropdown Menus

 

Project Proj5