-
-
Save imjacobclark/9943316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment