From 93a933af921172f2d1947baaef93a0d7778b643c Mon Sep 17 00:00:00 2001 From: Smig Tech Date: Thu, 12 Oct 2023 17:32:20 -0400 Subject: [PATCH] fix: add error handling for division --- calculator/js/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/calculator/js/script.js b/calculator/js/script.js index 84b6eee..a9855a8 100644 --- a/calculator/js/script.js +++ b/calculator/js/script.js @@ -84,6 +84,10 @@ function handleOperation() { let second = Number(ops.secondNum); let result = operate(first, second, ops.operator); // result = Math.round(result * (10^3)/(10^3)); + if (result === "error") { + ops.clear(); + return; + } result = result.toPrecision(3); updateDisplay(result); ops.firstNum = result;