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
31 lines (27 loc) · 651 Bytes
/
calculator.js
File metadata and controls
31 lines (27 loc) · 651 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
class Calculator {
add(a, b) {
return a + b;
}
subtract(a, b) {
return a - b;
}
multiply(a, b) {
return a * b;
}
divide(a, b) {
if (b === 0) {
throw new Error("Division by zero is not allowed.");
}
return a / b;
}
}
// Example usage
const calculator = new Calculator();
console.log("Addition: ", calculator.add(10, 5));
console.log("Subtraction: ", calculator.subtract(10, 5));
console.log("Multiplication: ", calculator.multiply(10, 5));
try {
console.log("Division: ", calculator.divide(10, 0));
} catch (error) {
console.error(error.message);
}