0% found this document useful (0 votes)
10 views6 pages

Doctype HTML

The document is an HTML code for an enhanced calculator web application featuring a user-friendly interface with a display and buttons for numbers and operations. It includes a dark mode toggle and supports keyboard input for ease of use. The calculator performs basic arithmetic operations and provides functionality for clearing the display and backspacing.

Uploaded by

sayafan321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Doctype HTML

The document is an HTML code for an enhanced calculator web application featuring a user-friendly interface with a display and buttons for numbers and operations. It includes a dark mode toggle and supports keyboard input for ease of use. The calculator performs basic arithmetic operations and provides functionality for clearing the display and backspacing.

Uploaded by

sayafan321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<!

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Enhanced Calculator</title>
<style>
*{
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
margin: 0;
padding: 0;
height: 100vh;
background: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%);
display: flex;
align-items: center;
justify-content: center;
transition: background 0.3s ease;
}

.calculator {
background: #ffffffdd;
padding: 20px 25px;
border-radius: 16px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
width: 320px;
position: relative;
}

.display {
width: 100%;
height: 60px;
font-size: 28px;
text-align: right;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 10px;
background: #f0f4f8;
color: #333;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
}

.btn {
padding: 20px;
font-size: 18px;
border: none;
border-radius: 12px;
background: linear-gradient(145deg, #e6e6e6, #ffffff);
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: 0.2s ease;
cursor: pointer;
}

.btn:hover {
background: #d0e6ff;
}

.operator {
background: #66a6ff;
color: white;
}

.equal {
background: #00c9a7;
color: white;
grid-column: span 2;
}

.clear {
background: #ff6b6b;
color: white;
grid-column: span 2;
}

/* Dark Mode Styles */


.dark-mode {
background: linear-gradient(135deg, #232526 0%, #414345 100%);
color: #eee;
}
.dark-mode .calculator {
background: #2c2c2c;
}

.dark-mode .display {
background: #444;
color: #eee;
}

.dark-mode .btn {
background: #333;
color: #eee;
}

.dark-mode .btn:hover {
background: #555;
}

/* Dark Mode Switch Toggle */


.dark-toggle {
position: absolute;
top: -50px;
right: 10px;
}

.switch {
position: relative;
display: inline-block;
width: 50px;
height: 26px;
}

.switch input {
opacity: 0;
width: 0;
height: 0;
}

.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 30px;
}

.slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .4s;
border-radius: 50%;
}

.switch input:checked + .slider {


background-color: #00c9a7;
}

.switch input:checked + .slider:before {


transform: translateX(24px);
}
</style>
</head>
<body>
<div class="calculator">
<div class="dark-toggle">
<label class="switch">
<input type="checkbox" onchange="toggleDarkMode()">
<span class="slider"></span>
</label>
</div>

<input type="text" class="display" id="display" disabled>


<div class="buttons">
<button class="btn" onclick="append('7')">7</button>
<button class="btn" onclick="append('8')">8</button>
<button class="btn" onclick="append('9')">9</button>
<button class="btn operator" onclick="append('/')">÷</button>
<button class="btn" onclick="append('4')">4</button>
<button class="btn" onclick="append('5')">5</button>
<button class="btn" onclick="append('6')">6</button>
<button class="btn operator" onclick="append('*')">×</button>

<button class="btn" onclick="append('1')">1</button>


<button class="btn" onclick="append('2')">2</button>
<button class="btn" onclick="append('3')">3</button>
<button class="btn operator" onclick="append('-')">−</button>

<button class="btn" onclick="append('0')">0</button>


<button class="btn" onclick="append('.')">.</button>
<button class="btn operator" onclick="append('+')">+</button>
<button class="btn equal" onclick="calculate()">=</button>

<button class="btn" onclick="backspace()">⌫</button>


<button class="btn clear" onclick="clearDisplay()">C</button>
</div>
</div>

<script>
const display = [Link]('display');

function append(value) {
[Link] += value;
}

function calculate() {
try {
[Link] = eval([Link]);
} catch {
[Link] = "Error";
}
}

function clearDisplay() {
[Link] = '';
}

function backspace() {
[Link] = [Link](0, -1);
}

function toggleDarkMode() {
[Link]('dark-mode');
}

[Link]("keydown", function(e) {
const key = [Link];
if ("0123456789.+-*/".includes(key)) {
append(key);
} else if (key === "Enter") {
calculate();
} else if (key === "Backspace") {
backspace();
} else if (key === "Escape") {
clearDisplay();
}
});
</script>
</body>
</html>

You might also like