Skip to content

Instantly share code, notes, and snippets.

@imjacobclark
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save imjacobclark/9943316 to your computer and use it in GitHub Desktop.

Select an option

Save imjacobclark/9943316 to your computer and use it in GitHub Desktop.

Revisions

  1. imjacobclark renamed this gist Apr 2, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. imjacobclark created this gist Apr 2, 2014.
    30 changes: 30 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    function Calculator(){

    this.add = function(num1, num2){
    if(this.isNumber([num1,num2]) == false){
    throw "error: invalid input to function.";
    }else{
    return num1 + num2;
    }
    }

    this.subtract = function(num1, num2){
    if(this.isNumber([num1,num2]) == false){
    throw "error: invalid input to function.";
    }else{
    return num1 - num2;
    }
    }

    this.isNumber = function(arr){
    //console.log(arr);
    for(var i=0; i <= arr.length; i++){
    //console.log(arr[i]);
    return (typeof(arr[i]) === 'number') ? true : false;
    }
    }

    }

    var calc = new Calculator();
    console.log(calc.add(1,"2"));