Created
March 3, 2017 06:41
-
-
Save WebCulT/aebb003b48fd8b73b3749a4f41c624ac to your computer and use it in GitHub Desktop.
The simple calculator
This file contains 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
'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