<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
margin: 0;
padding: 0;
background: #7AA5D2;
display: flex;
justify-content: center;
font-family: 'Poppins','Arial';
font-weight: 600;
background-color: black;
}
.container{
margin: 2rem 0;
width: 22rem;
height: 33rem;
background: #E8E8E8;
border-radius: 1rem;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.25);
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.screen_wrap{
margin: 2rem 0 1rem 0;
width: 18rem;
height: 5rem;
border-radius: 0.5rem;
background: #E8E8E8;
box-shadow: 6px 6px 12px #cfcfce,
-6px -6px 12px #ffffff;
display: flex;
justify-content: center;
align-items: center;
}
.screen_container{
width: 17rem;
height: 4rem;
border-radius: 0.25rem;
background: #BBBFCA;
box-shadow: 7px 7px 15px #9fa2ac,
inset -7px -7px 15px #d7dce8;
}
.screen{
padding-right: 7px;
width: 100%;
height: 70%;
color: #303841;
font-size: border-box;
text-align: right;
}
.history{
padding: 4px 7px 0 0;
width: 100%;
height: 30%;
font-size: 1rem;
color: #303841;
box-sizing: border-box;
opacity: 0.5;
}
.btn_wrap{
width: 20rem;
height: 22rem;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 1rem;
}
.btn{
all: unset;
width: 3.5rem;
height: 3.5rem;
font-size: 1.3rem;
color: #303841;
border-radius: 50%;
background: lightblue;
box-shadow: 5px 5px 10px #cfcfce,
-5px -5px 10px #ffffff;
display: grid;
place-content: center;
cursor: pointer;
}
.btn:nth-child(19){
width: 8rem;
border-radius: 4rem;
}
.btn:nth-child(3),
.btn:nth-child(4),
.btn:nth-child(8),
.btn:nth-child(12),
.btn:nth-child(16){
background: #9fc2e7;
}
.btn:nth-child(1),
.btn:nth-child(2),
.btn:nth-child(19){
background: #FECDA6;
}
</style>
</head>
<body>
<div class="container">
<div class="screen_wrap">
<div class="screen_container">
<div class="history"></div>
<div class="screen"></div>
</div>
</div>
<div class="btn_wrap">
<button class="btn">C</button>
<button class="btn">DEL</button>
<button class="btn">%</button>
<button class="btn">/</button>
<button class="btn">7</button>
<button class="btn">8</button>
<button class="btn">9</button>
<button class="btn">*</button>
<button class="btn">4</button>
<button class="btn">5</button>
<button class="btn">6</button>
<button class="btn">-</button>
<button class="btn">1</button>
<button class="btn">2</button>
<button class="btn">3</button>
<button class="btn">+</button>
<button class="btn">.</button>
<button class="btn">0</button>
<button class="btn">=</button>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
let historyDiv = document.querySelector('.history');
let screenDiv = document.querySelector('.screen');
document.querySelectorAll('.btn').forEach(button => {
button.addEventListener('click', function() {
let buttonText = this.innerText;
if (buttonText === 'C') {
screenDiv.innerText = '';
} else if (buttonText === 'DEL') {
screenDiv.innerText = screenDiv.innerText.slice(0, -1);
} else if (buttonText === '=') {
try {
let result = eval(screenDiv.innerText);
historyDiv.innerText = screenDiv.innerText + ' = ' + result;
screenDiv.innerText = result;
} catch (error) {
screenDiv.innerText = 'Error';
}
} else {
screenDiv.innerText += buttonText;
}
});
});
});
</script>
</script>
</body>
</html>