Skip to content

Add calculator module with basic arithmetic operations#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/create-simple-calculator-function
Draft

Add calculator module with basic arithmetic operations#1
Copilot wants to merge 2 commits intomainfrom
copilot/create-simple-calculator-function

Conversation

Copy link

Copilot AI commented Jan 12, 2026

Implements a calculator module supporting addition, subtraction, multiplication, and division with proper error handling and validation.

Implementation

  • src/calculator.js - Five functions: add(), subtract(), multiply(), divide(), and unified calculate(a, operator, b)
  • Input validation - Rejects non-numbers, NaN, Infinity; throws on division by zero
  • Error handling - Descriptive error messages for all edge cases

Testing

  • 43 tests covering normal operations, edge cases, and error conditions
  • 100% coverage across all code paths
  • Jest test framework with npm test and npm run test:coverage scripts

Usage

const { add, subtract, multiply, divide, calculate } = require('./src/calculator');

// Individual functions
add(5, 3);           // 8
subtract(10, 4);     // 6
multiply(7, 6);      // 42
divide(20, 4);       // 5

// Unified interface
calculate(5, '+', 3);   // 8
calculate(10, '-', 4);  // 6
calculate(7, '*', 6);   // 42
calculate(20, '/', 4);  // 5

// Error handling
divide(5, 0);        // throws "Division by zero is not allowed"
calculate(5, '%', 3); // throws "Unsupported operator: %"

Demo application in examples/demo.js shows all features. API documentation in CALCULATOR.md.

Original prompt

@develop-agent Task: Create a simple calculator function that supports addition, subtraction, multiplication, and division operations.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ntation

Co-authored-by: mickeygousset <20031479+mickeygousset@users.noreply.github.com>
Copilot AI changed the title [WIP] Add calculator function for basic operations Add calculator module with basic arithmetic operations Jan 12, 2026
Copilot AI requested a review from mickeygousset January 12, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants