-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.js
More file actions
47 lines (41 loc) · 1.07 KB
/
calc.js
File metadata and controls
47 lines (41 loc) · 1.07 KB
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
function add(a, b){
return parseInt(a)+parseInt(b);
}
function sub(a, b){
return parseInt(a)-parseInt(b);
}
function mul(a, b){
return parseInt(a)*parseInt(b);
}
function div(a, b){
return parseInt(a)/parseInt(b);
}
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
readline.question("Escolha (a/b/c/d): ", (esc) => {
readline.question('Number 1: ', (n1) => {
readline.question("Number 2: ", (n2) => {
// console.log("Processing...");
switch (esc){
case "a":
console.log("Result: " + add(n1, n2));
break;
case "b":
console.log("Result: " + sub(n1, n2));
break;
case "c":
console.log("Result: " + mul(n1, n2));
break;
case "d":
console.log("Result: " + div(n1, n2));
break;
default:
console.log("Errado!");
}
readline.close();
});
// readline.close();
});
});