Skip to content
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

Lack of Input Validation and Error Handling in Calculator #1164

Open
MakaremHind opened this issue Nov 14, 2024 · 2 comments
Open

Lack of Input Validation and Error Handling in Calculator #1164

MakaremHind opened this issue Nov 14, 2024 · 2 comments
Labels
good first issue Good for newcomers

Comments

@MakaremHind
Copy link

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;
    }
}
@MakaremHind MakaremHind added the good first issue Good for newcomers label Nov 14, 2024
Copy link

👋 @MakaremHind

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

@soniSanidhya
Copy link

hey assign this to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants