From 2cf413677ff20d42c95b6fe0f10e1d773bb535e4 Mon Sep 17 00:00:00 2001 From: chitra-dongare Date: Fri, 17 Oct 2025 22:23:39 +0530 Subject: [PATCH 1/2] Added working Calculator module for functions challenge --- .../app/challenges/functions/calculator.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 web/src/app/challenges/functions/calculator.js diff --git a/web/src/app/challenges/functions/calculator.js b/web/src/app/challenges/functions/calculator.js new file mode 100644 index 0000000..a280ef6 --- /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); + } + + // Expose public methods + 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()); From 3bdb2a95361594625ebc102cc53a4a9063e9ef4e Mon Sep 17 00:00:00 2001 From: chitra-dongare Date: Fri, 17 Oct 2025 22:30:58 +0530 Subject: [PATCH 2/2] Added working Calculator module for functions challenge --- web/src/app/challenges/functions/calculator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/app/challenges/functions/calculator.js b/web/src/app/challenges/functions/calculator.js index a280ef6..8c9bfe5 100644 --- a/web/src/app/challenges/functions/calculator.js +++ b/web/src/app/challenges/functions/calculator.js @@ -17,7 +17,7 @@ function Calculator(num1, num2) { return Math.floor(num1 / num2); } - // Expose public methods + return { sum, difference, product, dividend }; }