commit c0fe4da0279ba83d7bcb28080a5a3479a21ff3e5
parent c49301ebefc87946744d69aa2112a719c4bb46d5
Author: therealFIGBERT <figbertwelner@gmail.com>
Date: Mon, 25 Nov 2019 09:53:58 -0800
Add error handling for NaN and null/undefined in basic calculator
Diffstat:
1 file changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/components/basicCalc/basicHandler.js b/src/components/basicCalc/basicHandler.js
@@ -85,6 +85,9 @@ export class BasicCalc extends React.Component {
if (!isNaN(Number(this.state.input.slice(-1)))) {
// eslint-disable-next-line
final = eval(this.state.input);
+ if (final == null || isNaN(final)) {
+ final = 'ERROR';
+ }
} else {
final = 'ERROR';
}