Skip to content

Lack of Input Validation and Error Handling in Calculator #1164

Closed

Description

@MakaremHind

Lack of Input Validation and Error Handling in Calculator

Description:

The calculator currently lacks proper validation and error handling for various input cases. This can lead to unexpected behavior or incorrect results. Specifically, the following issues are present:

  • Division by zero is not handled, leading to undefined behavior.
  • Consecutive operators (e.g., 5 ++ 3) can be entered, causing calculation errors.
  • Multiple decimal points can be entered within a single number, leading to parsing issues.

Proposed Solution:

Implement validation checks for division by zero, multiple decimal points, and consecutive operators.
Add error handling to catch and display errors for invalid operations.

###Example Code:

function divide(a, b) {
    if (b === 0) {
        alert("Error: Division by zero is undefined.");
        return null;
    }
    return a / b;
}

function addOperator(operator) {
    if (!isNaN(display.value[display.value.length - 1])) { 
        display.value += operator;
    }
}

Activity

  1. github-actions commented on Nov 14, 2024

    @github-actions

    👋 @MakaremHind

    Thanks for opening your first issue here! Be sure to follow the issue template!

  2. soniSanidhya commented on Nov 17, 2024

    @soniSanidhya

    hey assign this to me

  3. amrit-GH23 commented on Mar 16, 2025

    @amrit-GH23

    Hi, please assign this issue to me

  4. bhpranit08 commented on Apr 13, 2025

    @bhpranit08

    Hi, can you please assign this issue to me?

  5. added a commit that references this issue on Aug 24, 2025
  6. durgesh846 commented on Sep 27, 2025

    @durgesh846

    Hi, I’d like to work on this issue. Can you please assign it to me?

  7. nikhilkumar1729 commented on Oct 13, 2025

    @nikhilkumar1729

    hey assign this to me

  8. Azhar-ud commented on Dec 7, 2025

    @Azhar-ud

    Hi I’m new to open source. Can I work on this issue?

  9. manya014 commented on Dec 16, 2025

    @manya014

    Hi, Can i work on this issue, i am new to open source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions