Skip to content

Instantly share code, notes, and snippets.

@rastating
Forked from imjacobclark/a.js
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rastating/9943394 to your computer and use it in GitHub Desktop.
Save rastating/9943394 to your computer and use it in GitHub Desktop.
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++){
if (typeof(arr[i]) !== 'number')) {
return false;
}
}
return true;
}
}
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