-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from tinkersain/tanisha
calculator file
- Loading branch information
Showing
4 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
* { | ||
box-sizing: border-box; | ||
} | ||
body { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
font-family: Arial, sans-serif; | ||
background: linear-gradient(45deg, #3dd3c4, #d69d5c); | ||
} | ||
.calculator { | ||
width: 320px; | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
background-color: #fff; | ||
} | ||
.display { | ||
width: 100%; | ||
height: 60px; | ||
background-color: #222; | ||
color: #fff; | ||
text-align: right; | ||
font-size: 2em; | ||
padding: 10px; | ||
border-radius: 5px; | ||
box-sizing: border-box; | ||
overflow: hidden; | ||
} | ||
.buttons { | ||
display: grid; | ||
grid-template-columns: repeat(4, 1fr); | ||
gap: 10px; | ||
margin-top: 20px; | ||
} | ||
.button { | ||
width: 100%; | ||
padding: 20px; | ||
font-size: 1.5em; | ||
text-align: center; | ||
border-radius: 5px; | ||
background-color: #f0f0f0; | ||
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1); | ||
cursor: pointer; | ||
user-select: none; | ||
} | ||
.button:active { | ||
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.2); | ||
} | ||
.button.operator { | ||
background-color: #f1a035; | ||
color: #fff; | ||
} | ||
.button.equal { | ||
background-color: #4caf50; | ||
color: #fff; | ||
grid-column: span 2; | ||
} | ||
.button.clear { | ||
background-color: #36b1f4; | ||
color: #fff; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Simple Calculator</title> | ||
<link rel="stylesheet" href="./calculator.css" /> | ||
<script src="./calculator.js"></script> | ||
</head> | ||
<body> | ||
<div class="calculator"> | ||
<div class="display" id="display">0</div> | ||
<div class="buttons"> | ||
<div class="button clear" onclick="clearDisplay()">C</div> | ||
<div class="button" onclick="appendToDisplay('7')">7</div> | ||
<div class="button" onclick="appendToDisplay('8')">8</div> | ||
<div class="button" onclick="appendToDisplay('9')">9</div> | ||
<div class="button operator" onclick="appendToDisplay('/')">/</div> | ||
<div class="button" onclick="appendToDisplay('4')">4</div> | ||
<div class="button" onclick="appendToDisplay('5')">5</div> | ||
<div class="button" onclick="appendToDisplay('6')">6</div> | ||
<div class="button operator" onclick="appendToDisplay('*')">*</div> | ||
<div class="button" onclick="appendToDisplay('1')">1</div> | ||
<div class="button" onclick="appendToDisplay('2')">2</div> | ||
<div class="button" onclick="appendToDisplay('3')">3</div> | ||
<div class="button operator" onclick="appendToDisplay('-')">-</div> | ||
<div class="button" onclick="appendToDisplay('0')">0</div> | ||
<div class="button" onclick="appendToDisplay('.')">.</div> | ||
<div class="button equal" onclick="calculate()">=</div> | ||
<div class="button operator" onclick="appendToDisplay('+')">+</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function clearDisplay() { | ||
document.getElementById("display").innerText = "0"; | ||
} | ||
|
||
function appendToDisplay(value) { | ||
const display = document.getElementById("display"); | ||
if (display.innerText === "0") { | ||
display.innerText = value; | ||
} else { | ||
display.innerText += value; | ||
} | ||
} | ||
|
||
function calculate() { | ||
const display = document.getElementById("display"); | ||
display.innerText = eval(display.innerText); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters