-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
42 lines (31 loc) · 913 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var Calculator = require('./src/calculator');
var Parser = require('./src/parser');
(() => {
var operation = process.argv[2].toUpperCase();
try{
var operand1 = Parser.parseOperand(process.argv[3]);
var operand2 = Parser.parseOperand(process.argv[4]);
// [,,operand1,operation,operand2] = process.argv
switch(operation){
case 'ADD':
// console.log(Calculator.sum(+operand1, +operand2));
console.log(Calculator.sum(operand1, operand2));
break;
case 'SUB':
console.log(Calculator.substract(operand1, operand2));
break;
case 'MUL':
console.log(Calculator.multiply(operand1, operand2));
break;
case 'DIV':
console.log(Calculator.divide(operand1, operand2));
break;
default:
console.log('Invalid operation!');
}
}
catch (e){
console.log('Error caught', e.message)
return;
}
})();