Lab 2

Home Lab 1 Assignment 1 Lab 2 Assignment 2 Lab 3 Assignment 3 Assignment 4 Research Paper

 

Points: 40

Due: 9/22/00

Submission Instruction: You are to publish your result on the ISU server, with a clearly labeled link to this assignment from your home page. Also, clearly label your answers.

  1. [5 pts: function] Write a JavaScript program that contains a function, call it isEven, that returns true if its argument is even and false otherwise. Write a function call to test your function.
  2. [5 pts: Loop, function] Write a JavaScript program that generates a sequence of even numbers between 1 and 100. Use the isEven function (above) to test for even numbers. Write only 10 numbers per line.
  3. [5 pts: Nested loop] Given a size N, write a JavaScript program that generates a NxN multiplication table. You need to use the HTML <table> construct for the multiplication table. A 3x3 example is given below.
1 2 3
2 4 6
3 6 9
  1. [5 pts: Validation: textarea, onBlur event] Create a form that contains an area for customer feedback. Check for the strings "~!@#" and "$%^&" (representing profanities) in the feedback area. If any of the two strings is contained in the area, provide a message that says "No profanity please!" Otherwise, give a message that says, "Thanks for your input." Perform the check when the area loses focus.
  2. [5 pts: Select] Write a JavaScript program to present the user with a drop-down list and when the user chooses an item from the list, go to the associated link for the item. Create the list with 4 items ("Choose a dept", "Dept A", "Dept B", and "Dept C") and go to deptA.htm, deptB.htm, and deptC.htm, respectively, when the user chooses Dept A, Dept B, and Dept C. Otherwise, don't do anything. Hint: use the onChange event handler.
  3. [10 pts: Object] Create an employee object that includes the following properties and methods:
  4. Name
    Department
    Hiredate
    Salary
    Display (method)
    Raise (method) -- this method takes a number representing the percentage of  raise as the argument.

    Use the following driver routine to test your Employee object type.

    emp1 = new employee("John", "IRS", "6/1/1993", 40000);
    emp2 = new employee("Mary", "DoD", "6/1/1993", 50000);

    emp1.display();
    emp1.raise(0.5); // 50% raise!
    emp1.display();

    emp2.display();
    emp2.raise(0.2);
    emp2.display();