forked from CloudLabsAI-Azure/Code-Generation-Refactoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.js
More file actions
41 lines (35 loc) · 999 Bytes
/
calculator.js
File metadata and controls
41 lines (35 loc) · 999 Bytes
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
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function askQuestion(query) {
return new Promise(resolve => rl.question(query, resolve));
}
async function main() {
const num1 = parseFloat(await askQuestion('Enter the first number: '));
const num2 = parseFloat(await askQuestion('Enter the second number: '));
const operation = await askQuestion('Enter the operation (+, -, *, /): ');
let result;
switch (operation) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
result = num1 / num2;
break;
default:
console.log('Invalid operation');
rl.close();
return;
}
console.log(`The result is: ${result}`);
rl.close();
}
main();