diff --git a/web/src/app/challenges/functions/calculator.js b/web/src/app/challenges/functions/calculator.js new file mode 100644 index 0000000..8c9bfe5 --- /dev/null +++ b/web/src/app/challenges/functions/calculator.js @@ -0,0 +1,29 @@ +// Calculator module that performs basic arithmetic operations +function Calculator(num1, num2) { + function sum() { + return num1 + num2; + } + + function difference() { + return num1 - num2; + } + + function product() { + return num1 * num2; + } + + function dividend() { + if (num2 === 0) return "Error: Division by zero!"; + return Math.floor(num1 / num2); + } + + + return { sum, difference, product, dividend }; +} + +// Example usage +const calc12And5 = Calculator(12, 5); +console.log("Sum:", calc12And5.sum()); +console.log("Difference:", calc12And5.difference()); +console.log("Product:", calc12And5.product()); +console.log("Dividend:", calc12And5.dividend());