Skip to content

Commit c370afc

Browse files
authored
Merge pull request #352 from parthivghose2919/working_calculator
functional calculator using Html,Css,JavaScript
2 parents 5bd5809 + b147ae2 commit c370afc

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function clearDisplay() {
2+
document.getElementById("display").value = '';
3+
}
4+
5+
function deleteLastCharacter() {
6+
let currentValue = document.getElementById("display").value;
7+
document.getElementById("display").value = currentValue.slice(0, -1);
8+
}
9+
10+
function toggleSign() {
11+
let currentValue = document.getElementById("display").value;
12+
if (currentValue.charAt(0) === "-") {
13+
document.getElementById("display").value = currentValue.slice(1);
14+
} else {
15+
document.getElementById("display").value = "+" + currentValue;
16+
}
17+
}
18+
19+
function appendToDisplay(value) {
20+
document.getElementById("display").value += value;
21+
}
22+
23+
function calculate() {
24+
try {
25+
let result = eval(document.getElementById("display").value);
26+
document.getElementById("display").value = result;
27+
} catch (error) {
28+
document.getElementById("display").value = "Error";
29+
}
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Real-Time Calculator</title>
7+
<link rel="stylesheet" href="styles.css" />
8+
</head>
9+
<body>
10+
<div class="calculator">
11+
<div class="input-section">
12+
<input
13+
type="text"
14+
id="expressioninput"
15+
placeholder="Enter an expression"
16+
/>
17+
</div>
18+
<div class="result-section">
19+
<div id="result">Result:</div>
20+
</div>
21+
</div>
22+
<script src="calculate.js"></script>
23+
</body>
24+
</html>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
* {
2+
font-family: Arial, sans-serif;
3+
background-color: #f4f4f4;
4+
}
5+
6+
.calculator {
7+
max-width: 400px;
8+
margin: 0 auto;
9+
background-color: #fff;
10+
padding: 20px;
11+
border-radius: 5px;
12+
}
13+
14+
.input-section {
15+
margin-bottom: 10px;
16+
}
17+
18+
#expressioninput {
19+
width: 100%;
20+
padding: 10px;
21+
border: 1px solid #ccc;
22+
border-radius: 3px;
23+
font-size: 16px;
24+
}
25+
26+
.result-section {
27+
background-color: #f0f0f0;
28+
padding: 10px;
29+
border-radius: 3px;
30+
}
31+
32+
#result {
33+
font-size: 18px;
34+
font-weight: bold;
35+
}

0 commit comments

Comments
 (0)