Skip to content

Instantly share code, notes, and snippets.

@byee01
Created September 15, 2011 20:54
Show Gist options
  • Save byee01/1220454 to your computer and use it in GitHub Desktop.
Save byee01/1220454 to your computer and use it in GitHub Desktop.
F12 67-328 Lab 1 - This gives you some clues about the parameters to expect based off of Google Closure's JS docs (http://code.google.com/closure/compiler/docs/js-for-compiler.html). Email brian.a.yee@gmail.com if you have any questions or leave a comment
/**
* TASK 1 - Create a basic calculator
*
* Create a function that takes 3 arguments: operator, operand1, operand2
* operator can be "add" "subtract" "multiply" or "divide"
* return the result of the operation on the operands
* return null if the operator argument is not one of the 4
* no other errors or exceptions need to be handled
* use a switch statement to choose the right operator
*
* @param {String} operator The type of operation "add" ... etc.
* @param {Integer} operand1
* @param {Integer} operand2
*/
function calculator
/*
* TASK 2a - Throw an error
*
* Improve your calculator by testing for divide by zero and throw exception
* In the case that the 2nd operand is zero, throw a new Error and give it a
* reasonable message.
*
* @param {String} operator The type of operation "add" ... etc.
* @param {Integer} operand1
* @param {Integer} operand2
*/
function calculatorWithZero
/*
* TASK 2b - Catch an error
* Write a function usecalculator() that invokes your calculator function
* 5 times. For the first 4, demonstrate that your calculator does the 4
* operations. For the fifth, try to divide by zero and catch the resulting
* exception. All your test cases should be within the try statement.
* When values are returned from the calculator function, merely print them
* to the console.log().
*/
function useCalculator() ...
/*
* TASK 3 - Variable number of arguments
*
* Create a sum function that will take a variable number of parameters and
* return their sum
*
* @param {...number} var_args Any random number of variables.
*/
function sum...
/*
* TASK 4 - Objects and methods
*
* Create a counter, as a literal object, that starts a count at zero and has
* methods increment, report, and reset (to zero).
* report should print the current count to console.log
*/
var counter = { ...
/*
* TASK 5 - Synthetic events
*
* Create two events, pingEvent and pongEvent
* Each event handler should:
* alert(e.message) where the message is "Ping" or "Pong"
* then setTimeout for 1500ms to dispatch the other event
* do this up to 3 times, then don't dispatch any longer
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment