Square root #6

Open
opened 2026-11-21 02:25:12 +00:00 by lab-admin · 1 comment
Owner

Add a square root operation. It is the first unary operation, so the API must accept it without b.

Requirements

  • API: GET /api/calculate?a=<number>&op=sqrt returns {"result": Math.sqrt(a)}. b is not required for sqrt and is ignored if present.
  • Square root of a negative number returns 400 {"error": "square root of a negative number"}.
  • Binary operations still require both a and b.
  • UI: a √ button that applies to the number currently on the display immediately (no = needed). Pressing 8, 1, √ shows 9; a negative input shows Error.
  • Tests in the module, API and page.

Acceptance criteria

  1. /api/calculate?a=81&op=sqrt returns {"result":9}.
  2. /api/calculate?a=2&op=sqrt returns a result between 1.41421 and 1.41422.
  3. /api/calculate?a=-4&op=sqrt returns 400 {"error":"square root of a negative number"}.
  4. /api/calculate?a=1&op=add (missing b) still returns 400.
  5. The page has a working √ button.
Add a square root operation. It is the first unary operation, so the API must accept it without `b`. ## Requirements - API: `GET /api/calculate?a=<number>&op=sqrt` returns `{"result": Math.sqrt(a)}`. `b` is not required for `sqrt` and is ignored if present. - Square root of a negative number returns `400 {"error": "square root of a negative number"}`. - Binary operations still require both `a` and `b`. - UI: a `√` button that applies to the number currently on the display immediately (no `=` needed). Pressing `8`, `1`, `√` shows `9`; a negative input shows `Error`. - Tests in the module, API and page. ## Acceptance criteria 1. `/api/calculate?a=81&op=sqrt` returns `{"result":9}`. 2. `/api/calculate?a=2&op=sqrt` returns a result between 1.41421 and 1.41422. 3. `/api/calculate?a=-4&op=sqrt` returns 400 `{"error":"square root of a negative number"}`. 4. `/api/calculate?a=1&op=add` (missing b) still returns 400. 5. The page has a working `√` button.
Collaborator

Aira · queued

Aira picked up this task. Branch aira/6-square-root.

**Aira · queued** Aira picked up this task. Branch `aira/6-square-root`.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/web-calculator-2#6
No description provided.