diff --git a/script.js b/script.js index 4c8aa9d..53ad0b9 100644 --- a/script.js +++ b/script.js @@ -21,7 +21,11 @@ class Calculator { } chooseOperation(operation) { - if (this.currentOperand === '') return + if (this.currentOperand === '' || this.currentOperand === '-') { + if (this.currentOperand === '-' && operation === '-') return; // Prevent adding multiple '-' signs + this.currentOperand += operation; // Append the '-' sign to the current operand + return; + } if (this.previousOperand !== '') { this.compute() } @@ -123,4 +127,4 @@ allClearButton.addEventListener('click', button => { deleteButton.addEventListener('click', button => { calculator.delete() calculator.updateDisplay() -}) \ No newline at end of file +})