-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
55 lines (43 loc) · 1.1 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
var prompt = require("prompt-sync")();
var calculator = require("./calculator");
var readInput = () => {
console.log("Welcome to the calculator. Choose one of the following options");
console.log("1. add");
console.log("2. subtract");
console.log("3. multiply");
console.log("4. divide");
console.log("5. exit");
var option = prompt(">> ");
if (option !== "5") {
console.log("Enter the first number");
let a = prompt(">> ");
console.log("Enter the second number");
let b = prompt(">> ");
let c;
switch(option){
case "1": {
c = calculator.add(a, b);
console.log(`a + b = ${c}`);
}
break;
case "2": {
c = calculator.subtract(a, b);
console.log(`a - b = ${c}`);
}
break;
case "3": {
c = calculator.multiply(a, b);
console.log(`a * b = ${c}`);
}
break;
case "4": {
c = calculator.divide(a, b);
console.log(`a / b = ${c}`);
}
break;
}
readInput();
}
}
readInput();
console.log("Thank you for using calculator. Good Bye");