Skip to content

Instantly share code, notes, and snippets.

@WebCulT
Created March 3, 2017 06:41
Show Gist options
  • Save WebCulT/aebb003b48fd8b73b3749a4f41c624ac to your computer and use it in GitHub Desktop.
Save WebCulT/aebb003b48fd8b73b3749a4f41c624ac to your computer and use it in GitHub Desktop.
The simple calculator
'use strict';
var Calculator = function() {
var obj = this, a, b, c;
var allValue = {
'+': function() {
return a + b;
},
'-': function() {
return a - b;
},
'/': function() {
return a / b;
},
'*': function() {
return a * b;
}
};
this.getReady = function() {
a = +prompt('First number', '');
b = +prompt('Last number', '');
c = prompt('Your action', '');
checkOut();
}
this.getAnswer = function() {
alert(allValue[c]());
};
function check() {
if(isNaN(a) || isNaN(b) || !allValue[c]) {
alert('Sorry, but your entry is uncorrect')
} else {
return obj.getAnswer();
}
}
};
var calc = new Calculator();
calc.getReady();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment