Skip to content

fix: add input validation to prevent errors in calculator#1240

Closed
Suraj-H675 wants to merge 1 commit into
thinkswell:masterfrom
Suraj-H675:fix/issue-1164-v3
Closed

fix: add input validation to prevent errors in calculator#1240
Suraj-H675 wants to merge 1 commit into
thinkswell:masterfrom
Suraj-H675:fix/issue-1164-v3

Conversation

@Suraj-H675
Copy link
Copy Markdown

What problem does this solve?

Prevents errors when using the calculator - blocks division by zero, multiple decimal points, and consecutive operators.

What changed and why?

  • Added hasDecimalInCurrentNumber() to detect decimal points in the current number
  • Added hasConsecutiveOperators() to detect consecutive operator presses
  • Modified NumberButtonClick() to prevent /0, multiple decimals, and consecutive operators
  • Modified functionButton() to validate expressions before evaluation

How was this tested?

Manual testing of all validation cases:

  • 5/0 shows error alert
  • 5..3 shows error alert
  • 5++3 replaces consecutive operator

Checklist

  • Read CONTRIBUTING.md
  • Changes match project coding style
  • All existing files preserved (index.html, style.css unchanged)

This contribution was created with AI assistance, with human review and approval at each step.

Prevents division by zero, multiple decimal points, and consecutive operators.

- Added hasDecimalInCurrentNumber() validation
- Added hasConsecutiveOperators() validation
- Modified NumberButtonClick() and functionButton() with validation

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Suraj-H675 Suraj-H675 closed this by deleting the head repository May 23, 2026
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