javascript-mini-projects icon indicating copy to clipboard operation
javascript-mini-projects copied to clipboard

Lack of Input Validation and Error Handling in Calculator

Open MakaremHind opened this issue 1 year ago • 7 comments

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 avatar Nov 14 '24 23:11 MakaremHind

👋 @MakaremHind

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

github-actions[bot] avatar Nov 14 '24 23:11 github-actions[bot]

hey assign this to me

soniSanidhya avatar Nov 17 '24 07:11 soniSanidhya

Hi, please assign this issue to me

amrit-GH23 avatar Mar 16 '25 07:03 amrit-GH23

Hi, can you please assign this issue to me?

bhpranit08 avatar Apr 13 '25 07:04 bhpranit08

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

durgesh846 avatar Sep 27 '25 08:09 durgesh846

hey assign this to me

nikhilkumar1729 avatar Oct 13 '25 14:10 nikhilkumar1729