-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 thepower
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) }, |
There was a problem hiding this comment.
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.
'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) }, |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.
<button class="btn" onClick="operationPressed('^')">^</button> | |
<button class="btn" onClick="operationPressed('^')" aria-label="power operation">^</button> |
Copilot uses AI. Check for mistakes.
Backend changes:
api/controller.js
: Added a new functionpower
to handle exponentiation in theexports.calculate
method.Frontend changes:
public/client.js
: Updated thecalculate
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.