Last active
August 29, 2015 14:08
-
-
Save ZucchiniZe/0a57cb7805523ade8a41 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
| module.exports = { | |
| add: function(a, b) { | |
| return a + b; | |
| }, | |
| sub: function(a, b) { | |
| return a - b; | |
| }, | |
| multi: function(a, b) { | |
| return a * b; | |
| }, | |
| div: function(a, b) { | |
| return a / b | |
| } | |
| } |
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
| var prompt = require('prompt'); | |
| var calc = require('./calc') | |
| prompt.colors = false; | |
| prompt.start(); | |
| prompt.get(['operator', 'number1', 'number2'], function (err, result) { | |
| if (err) { return onErr(err); } | |
| console.log('Output:'); | |
| console.log(' operator: ' + result.operator); | |
| console.log(' answer: ' + doCalc(result.operator, Number(result.number1), Number(result.number2))); | |
| }); | |
| var doCalc = function(operator, a, b) { | |
| switch (operator) { | |
| case "+": | |
| return calc.add(a, b); | |
| case "-": | |
| return calc.sub(a, b); | |
| case "*": | |
| return calc.multi(a, b); | |
| case "/": | |
| return calc.div(a, b); | |
| } | |
| } |
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
| { | |
| "name": "calc", | |
| "version": "1.0.0", | |
| "description": "a calculator to beat davids", | |
| "main": "index.js", | |
| "dependencies": { | |
| "prompt": "^0.2.14" | |
| }, | |
| "devDependencies": {}, | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "alex", | |
| "license": "MIT" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment