|
|
|
@ -82,11 +82,11 @@
|
|
|
|
<button class="clear" onclick="clearAll()">AC</button>
|
|
|
|
<button class="clear" onclick="clearAll()">AC</button>
|
|
|
|
<button class="clear" onclick="clearEntry()">C</button>
|
|
|
|
<button class="clear" onclick="clearEntry()">C</button>
|
|
|
|
<button class="operator" onclick="appendOperator('%')">%</button>
|
|
|
|
<button class="operator" onclick="appendOperator('%')">%</button>
|
|
|
|
<button class="toggle-sign" onclick="toggleSign()">+/-</button>
|
|
|
|
<button class="operator" onclick="appendOperator('÷')">÷</button>
|
|
|
|
<button onclick="appendDigit('7')">7</button>
|
|
|
|
<button onclick="appendDigit('7')">7</button>
|
|
|
|
<button onclick="appendDigit('8')">8</button>
|
|
|
|
<button onclick="appendDigit('8')">8</button>
|
|
|
|
<button onclick="appendDigit('9')">9</button>
|
|
|
|
<button onclick="appendDigit('9')">9</button>
|
|
|
|
<button class="operator" onclick="appendOperator('÷')">÷</button>
|
|
|
|
<button class="operator" onclick="appendOperator('×')">×</button>
|
|
|
|
<button onclick="appendDigit('4')">4</button>
|
|
|
|
<button onclick="appendDigit('4')">4</button>
|
|
|
|
<button onclick="appendDigit('5')">5</button>
|
|
|
|
<button onclick="appendDigit('5')">5</button>
|
|
|
|
<button onclick="appendDigit('6')">6</button>
|
|
|
|
<button onclick="appendDigit('6')">6</button>
|
|
|
|
@ -95,8 +95,9 @@
|
|
|
|
<button onclick="appendDigit('2')">2</button>
|
|
|
|
<button onclick="appendDigit('2')">2</button>
|
|
|
|
<button onclick="appendDigit('3')">3</button>
|
|
|
|
<button onclick="appendDigit('3')">3</button>
|
|
|
|
<button class="operator" onclick="appendOperator('+')">+</button>
|
|
|
|
<button class="operator" onclick="appendOperator('+')">+</button>
|
|
|
|
<button onclick="appendDigit('0')" style="grid-column: span 2;">0</button>
|
|
|
|
<button onclick="appendDigit('0')">0</button>
|
|
|
|
<button onclick="appendDigit('.')">.</button>
|
|
|
|
<button onclick="appendDigit('.')">.</button>
|
|
|
|
|
|
|
|
<button class="toggle-sign" onclick="toggleSign()">+/-</button>
|
|
|
|
<button class="equals" onclick="calculate()">=</button>
|
|
|
|
<button class="equals" onclick="calculate()">=</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
@ -190,18 +191,24 @@
|
|
|
|
clearAll();
|
|
|
|
clearAll();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
operator = '';
|
|
|
|
|
|
|
|
previousInput = '';
|
|
|
|
currentInput = '';
|
|
|
|
currentInput = '';
|
|
|
|
let lastValidInput = '';
|
|
|
|
let buffer = '';
|
|
|
|
for (let item of history) {
|
|
|
|
for (let item of history) {
|
|
|
|
if (/[0-9.]/.test(item)) {
|
|
|
|
if (item === '+/-') {
|
|
|
|
currentInput += item;
|
|
|
|
buffer = buffer
|
|
|
|
lastValidInput = currentInput;
|
|
|
|
? (buffer.startsWith('-') ? buffer.slice(1) : '-' + buffer)
|
|
|
|
} else if (item !== '+/-') {
|
|
|
|
: '-';
|
|
|
|
|
|
|
|
} else if (/[0-9.]/.test(item)) {
|
|
|
|
|
|
|
|
buffer += item;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
previousInput = buffer;
|
|
|
|
operator = item;
|
|
|
|
operator = item;
|
|
|
|
previousInput = lastValidInput;
|
|
|
|
buffer = '';
|
|
|
|
currentInput = '';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentInput = buffer;
|
|
|
|
expression = operator ? `${previousInput}${operator}${currentInput}` : currentInput || '0';
|
|
|
|
expression = operator ? `${previousInput}${operator}${currentInput}` : currentInput || '0';
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
clearAll();
|
|
|
|
clearAll();
|
|
|
|
|