Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a simple calculator app integrated with UI with help of HTML CSS and JS #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Web Devlopment Project/CalculatorApp/Read Me
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a simple calculator app integrated with UI with help of HTML CSS and JS
31 changes: 31 additions & 0 deletions Web Devlopment Project/CalculatorApp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div class="calculator">
<input type="text" id="result" readonly />
<div class="buttons">
<button onclick="clearResult()">C</button>
<button onclick="appendToResult('7')">7</button>
<button onclick="appendToResult('8')">8</button>
<button onclick="appendToResult('9')">9</button>
<button onclick="appendToResult('/')">/</button>
<button onclick="appendToResult('4')">4</button>
<button onclick="appendToResult('5')">5</button>
<button onclick="appendToResult('6')">6</button>
<button onclick="appendToResult('*')">*</button>
<button onclick="appendToResult('1')">1</button>
<button onclick="appendToResult('2')">2</button>
<button onclick="appendToResult('3')">3</button>
<button onclick="appendToResult('-')">-</button>
<button onclick="appendToResult('0')">0</button>
<button onclick="calculateResult()">=</button>
<button onclick="appendToResult('+')">+</button>
</div>
</div>

<script src="script.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions Web Devlopment Project/CalculatorApp/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let result = "";

function appendToResult(value) {
result += value;
document.getElementById("result").value = result;
}

function clearResult() {
result = "";
document.getElementById("result").value = result;
}

function calculateResult() {
try {
result = eval(result);
document.getElementById("result").value = result;
} catch (e) {
result = "Error";
document.getElementById("result").value = result;
}
}
47 changes: 47 additions & 0 deletions Web Devlopment Project/CalculatorApp/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.calculator {
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
padding: 20px;
text-align: center;
}

input[type="text"] {
width: 100%;
font-size: 24px;
margin-bottom: 10px;
border: none;
background-color: #fff;
}

.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 10px;
grid-auto-rows: minmax(50px, auto);
justify-content: center;
}

button {
font-size: 24px;
padding: 10px;
background-color: #333;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s;
}

button:hover {
background-color: #555;
}