COP 2500 Spring 2012

Lab #6

Home Labs Lecture Notes
 

Deliverables: To complete this assignment you must --

  1. Write an HTML document with embedded Javascript according to the instructions.
  2. Email your instructor what you have completed. You can get partial credit even if not fully completed with the lab.

Introduction: The goal of this assignment is to give you experience working with functions. You will create a simple calculator by programming the basic functions.


Procedures:
  1. Use a text editor to complete your assignment.
  2. Using your text editor create a new document named "cop2500lab6.html". Use the document here as the starting point. You may change the arrangement to your liking, but there must be a method to input 2 numbers and at least the 4 buttons to select the operation as well as a method to confirm the result.
  3. Using functions in Javascript, perform the operation the user clicks on and display the results in the form text box named answer.

    Review Lab 6: Functions for help using functions.

    Calculator
    SectionPseudocodeComments
    INPUT:var x, y; These are obtained from from text boxes n1 and n2.
    OTHER VARIABLES:var result;
    INITIALIZATION: n1 and n2 must be provided by the user.
    COMPUTATION: Add: result = x + y;

    Subtract: result = x - y;

    Multiply: result = x * y;

    Divide: result = x / y;

    OUTPUT:return(result); Remember to place the result in the form text box named answer

  4. Open a browser and verify that the file displays properly.