Skip to content

added power function #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

added power function #34

wants to merge 1 commit into from

Conversation

stargazer4
Copy link
Contributor

Backend changes:

  • api/controller.js: Added a new function power to handle exponentiation in the exports.calculate method.

Frontend changes:

  • public/client.js: Updated the calculate function to handle the new '^' operation by appending the appropriate query parameter.
  • public/index.html: Added a new button for the '^' operation in the calculator interface.

@stargazer4 stargazer4 requested a review from Copilot May 15, 2025 18:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for exponentiation (^) across the backend controller, frontend request handling, and UI.

  • Introduces a new power operation in the calculation API
  • Updates the client to include ^ mapping to the power query parameter
  • Adds a ^ button to the calculator UI

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
public/index.html Added a ^ button for exponentiation
public/client.js Updated calculate() to handle ^power
api/controller.js Implemented the power function using Math.pow
Comments suppressed due to low confidence (2)

api/controller.js:19

  • Add unit tests for the new 'power' operation in the controller to ensure correct exponentiation behavior, including edge cases like zero and negative exponents.
'power': function(a, b) { return Math.pow(a, b) },

public/client.js:36

  • Add frontend unit tests for calculate() to verify that the '^' operation correctly appends ?operation=power to the request URI.
case '^':

@@ -16,6 +16,7 @@ exports.calculate = function(req, res) {
'subtract': function(a, b) { return a - b },
'multiply': function(a, b) { return a * b },
'divide': function(a, b) { return a / b },
'power': function(a, b) { return Math.pow(a, b) },
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using the ES operator (a ** b) for exponentiation instead of Math.pow for improved readability and consistency with modern JS syntax.

Suggested change
'power': function(a, b) { return Math.pow(a, b) },
'power': function(a, b) { return a ** b },

Copilot uses AI. Check for mistakes.

@@ -16,6 +16,7 @@ exports.calculate = function(req, res) {
'subtract': function(a, b) { return a - b },
'multiply': function(a, b) { return a * b },
'divide': function(a, b) { return a / b },
'power': function(a, b) { return Math.pow(a, b) },
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the API’s JSDoc or external documentation for the calculate endpoint to include details about the new power operation and its expected inputs/outputs.

Copilot uses AI. Check for mistakes.

@@ -40,6 +40,8 @@
<button class="btn" onClick="operationPressed('+')">+</button>
<button class="btn" onClick="equalPressed()">=</button>

<button class="btn" onClick="operationPressed('^')">^</button>
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an aria-label (e.g., aria-label="power operation") to the ^ button to ensure it’s accessible to screen readers.

Suggested change
<button class="btn" onClick="operationPressed('^')">^</button>
<button class="btn" onClick="operationPressed('^')" aria-label="power operation">^</button>

Copilot uses AI. Check for mistakes.

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.

1 participant