A calculator

<!DOCTYPE html>

<html lang=“en”>
<head>
<meta charset=“UTF-8”>
<title>Calculator</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #1e1e2f;
font-family: Arial, sans-serif;
}

.calculator {
background: #2c2c3e;
padding: 20px;
border-radius: 15px;
box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.display {
width: 100%;
height: 60px;
margin-bottom: 15px;
text-align: right;
padding: 10px;
font-size: 24px;
border: none;
border-radius: 10px;
background: #000;
color: #0f0;
}

.buttons {
display: grid;
grid-template-columns: repeat(4, 70px);
gap: 10px;
}

button {
height: 60px;
font-size: 18px;
border: none;
border-radius: 10px;
cursor: pointer;
background: #3e3e55;
color: white;
transition: 0.2s;
}

button:hover {
background: #57577a;
}

.operator {
background: #ff9500;
}

.equal {
background: #28a745;
grid-column: span 2;
}

.clear {
background: #dc3545;
grid-column: span 2;
}
</style>
</head>
<body>

<div class=“calculator”>
<input type=“text” id=“display” class=“display” disabled>

<div class=“buttons”>
<button onclick=clearDisplay() class=“clear”>C</button>
<button onclick=append(‘/’)></button>
<button onclick=append(‘*’)></button>

<button onclick=append(‘7’)>7</button>
<button onclick=append(‘8’)>8</button>
<button onclick=append(‘9’)>9</button>
<button onclick=append(‘-‘) class=“operator”></button>

<button onclick=append(‘4’)>4</button>
<button onclick=append(‘5’)>5</button>
<button onclick=append(‘6’)>6</button>
<button onclick=append(‘+’) class=“operator”>+</button>

<button onclick=append(‘1’)>1</button>
<button onclick=append(‘2’)>2</button>
<button onclick=append(‘3’)>3</button>
<button onclick=calculate() class=“equal”>=</button>

<button onclick=append(‘0’)>0</button>
<button onclick=append(‘.’)>.</button>
</div>
</div>

<script>
let display = document.getElementById(“display”);

function append(value) {
display.value += value;
}

function clearDisplay() {
display.value = “”;
}

function calculate() {
try {
display.value = eval(display.value);
} catch {
display.value = “Error”;
}
}
</script>

</body>
</html>

WRITE MY PAPER

Comments

Leave a Reply