Added codes and softcopy.
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Calculator</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="calculator">
|
||||
<h1>Calculator</h1>
|
||||
<p class="designer">(Designed by Kshitij)</p>
|
||||
<div class="display">
|
||||
<input type="text" id="result" readonly>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button onclick="clearDisplay()">C</button>
|
||||
<button onclick="calculate('/')">/</button>
|
||||
<button onclick="calculate('*')">*</button>
|
||||
<button onclick="calculate('-')">-</button>
|
||||
<button onclick="addToDisplay('7')">7</button>
|
||||
<button onclick="addToDisplay('8')">8</button>
|
||||
<button onclick="addToDisplay('9')">9</button>
|
||||
<button onclick="calculate('+')">+</button>
|
||||
<button onclick="addToDisplay('4')">4</button>
|
||||
<button onclick="addToDisplay('5')">5</button>
|
||||
<button onclick="addToDisplay('6')">6</button>
|
||||
<button onclick="calculate('=')">=</button>
|
||||
<button onclick="addToDisplay('1')">1</button>
|
||||
<button onclick="addToDisplay('2')">2</button>
|
||||
<button onclick="addToDisplay('3')">3</button>
|
||||
<button onclick="addToDisplay('0')">0</button>
|
||||
<button onclick="addToDisplay('.')">.</button>
|
||||
</div>
|
||||
</div>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
let currentValue = '';
|
||||
|
||||
function addToDisplay(value) {
|
||||
currentValue += value;
|
||||
document.getElementById('result').value = currentValue;
|
||||
}
|
||||
|
||||
function clearDisplay() {
|
||||
currentValue = '';
|
||||
document.getElementById('result').value = '';
|
||||
}
|
||||
|
||||
function calculate(operator) {
|
||||
if (operator === '=') {
|
||||
try {
|
||||
currentValue = eval(currentValue).toString();
|
||||
document.getElementById('result').value = currentValue;
|
||||
} catch (error) {
|
||||
alert('Invalid expression');
|
||||
clearDisplay();
|
||||
}
|
||||
} else {
|
||||
if (currentValue === '') {
|
||||
alert('Please enter a number');
|
||||
return;
|
||||
}
|
||||
currentValue += operator;
|
||||
document.getElementById('result').value = currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.calculator {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.designer {
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.display {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.display input {
|
||||
width: 100%;
|
||||
font-size: 24px;
|
||||
padding: 5px;
|
||||
text-align: right;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
grid-gap: 5px;
|
||||
}
|
||||
|
||||
.buttons button {
|
||||
font-size: 18px;
|
||||
padding: 10px;
|
||||
background-color: #f0f0f0;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.buttons button:hover {
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user