Skip to content

Commit b7bc82b

Browse files
Intial Commit
0 parents  commit b7bc82b

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

index.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="stylesheet" href="style.css" />
8+
<title>Calculator - By Hariom Gupta</title>
9+
</head>
10+
<body>
11+
<div class="container">
12+
<div class="calculator">
13+
<input type="text" id="inputBox" placeholder="0" />
14+
<div>
15+
<button class="button operator">AC</button>
16+
<button class="button operator">DEL</button>
17+
<button class="button operator">%</button>
18+
<button class="button operator">/</button>
19+
</div>
20+
<div>
21+
<button class="button">7</button>
22+
<button class="button">8</button>
23+
<button class="button">9</button>
24+
<button class="button operator">*</button>
25+
</div>
26+
<div>
27+
<button class="button">4</button>
28+
<button class="button">5</button>
29+
<button class="button">6</button>
30+
<button class="button operator">-</button>
31+
</div>
32+
<div>
33+
<button class="button">1</button>
34+
<button class="button">2</button>
35+
<button class="button">3</button>
36+
<button class="button operator">+</button>
37+
</div>
38+
39+
<div>
40+
<button class="button">00</button>
41+
<button class="button">0</button>
42+
<button class="button">.</button>
43+
<button class="button equalBtn">=</button>
44+
</div>
45+
</div>
46+
</div>
47+
48+
<script src="script.js"></script>
49+
</body>
50+
</html>

script.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let input = document.getElementById('inputBox');
2+
let buttons = document.querySelectorAll('button');
3+
4+
let string = "";
5+
let arr = Array.from(buttons);
6+
arr.forEach(button => {
7+
button.addEventListener('click', (e) =>{
8+
if(e.target.innerHTML == '='){
9+
string = eval(string);
10+
input.value = string;
11+
}
12+
13+
else if(e.target.innerHTML == 'AC'){
14+
string = "";
15+
input.value = string;
16+
}
17+
else if(e.target.innerHTML == 'DEL'){
18+
string = string.substring(0, string.length-1);
19+
input.value = string;
20+
}
21+
else{
22+
string += e.target.innerHTML;
23+
input.value = string;
24+
}
25+
26+
})
27+
})

style.css

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500&display=swap');
2+
3+
*{
4+
margin: 0;
5+
padding: 0;
6+
box-sizing: border-box;
7+
font-family: 'Poppins', sans-serif;
8+
}
9+
10+
body{
11+
width: 100%;
12+
height: 100vh;
13+
display: flex;
14+
justify-content: center;
15+
align-items: center;
16+
background: linear-gradient(50deg, #07363e, #2d3239);
17+
}
18+
19+
.calculator{
20+
border: 1px solid #717377;
21+
padding: 20px;
22+
border-radius: 16px;
23+
background: transparent;
24+
box-shadow: 0px 3px 15px rgba(113, 115, 119, 0.5);
25+
26+
}
27+
28+
input{
29+
width: 320px;
30+
border: none;
31+
padding: 24px;
32+
margin: 10px;
33+
background: transparent;
34+
box-shadow: 0px 3px 15px rgbs(84, 84, 84, 0.1);
35+
font-size: 40px;
36+
text-align: right;
37+
cursor: pointer;
38+
color: #ffffff;
39+
}
40+
41+
input::placeholder{
42+
color: #ffffff;
43+
}
44+
45+
button{
46+
border: none;
47+
width: 60px;
48+
height: 60px;
49+
margin: 10px;
50+
border-radius: 20%;
51+
background: transparent;
52+
color: #ffffff;
53+
font-size: 20px;
54+
box-shadow: -8px -8px 15px rgba(255, 255, 255, 0.1);
55+
cursor: pointer;
56+
}
57+
58+
.equalBtn{
59+
background-color: #61a80b;
60+
}
61+
62+
.operator{
63+
color: #0ec6ff;
64+
}

0 commit comments

Comments
 (0)