Temperature / script.js
Fouzanjaved's picture
Create script.js
8e2f3c4 verified
raw
history blame
833 Bytes
const display = document.getElementById('display');
function clearDisplay() {
display.textContent = '0';
}
function deleteLast() {
if (display.textContent.length === 1) {
display.textContent = '0';
} else {
display.textContent = display.textContent.slice(0, -1);
}
}
function appendNumber(number) {
if (display.textContent === '0') {
display.textContent = number;
} else {
display.textContent += number;
}
}
function appendOperator(operator) {
const operators = ['+', '-', '*', '/', '%'];
if (!operators.includes(display.textContent.slice(-1))) {
display.textContent += operator;
}
}
function calculateResult() {
try {
display.textContent = eval(display.textContent);
} catch (error) {
display.textContent = 'Error';
}
}