Skip to content

Commit e88c350

Browse files
authored
Merge pull request #709 from Shiva-Sai-ssb/SimpleCalculator-shiva-sai-ssb
chore: Add Calculator Project
2 parents b5df1a8 + 7b84758 commit e88c350

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<!--Meta tag is used to make the webpage reponsive, controls page dimension and scaling-->
5+
<meta name="viewport" content="width=device-width, initail-scale=1.0" />
6+
<title>Simple Calculator</title>
7+
<link rel="stylesheet" href="style.css" />
8+
</head>
9+
<body>
10+
<div class="calc">
11+
<input type="text" placeholder="0" id="inputbox" />
12+
<div>
13+
<button class="operator">AC</button>
14+
<button class="operator">DEL</button>
15+
<button class="operator">%</button>
16+
<button class="operator">/</button>
17+
</div>
18+
<div>
19+
<button>7</button>
20+
<button>8</button>
21+
<button>9</button>
22+
<button class="operator">*</button>
23+
</div>
24+
<div>
25+
<button>4</button>
26+
<button>5</button>
27+
<button>6</button>
28+
<button class="operator">-</button>
29+
</div>
30+
<div>
31+
<button>1</button>
32+
<button>2</button>
33+
<button>3</button>
34+
<button class="operator">+</button>
35+
</div>
36+
<div>
37+
<button>0</button>
38+
<button>00</button>
39+
<button class="operator">.</button>
40+
<button class="equal-btn">=</button>
41+
</div>
42+
</div>
43+
<script src="myscript.js"></script>
44+
</body>
45+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
let input = document.getElementById("inputbox");
2+
input.addEventListener('keypress', (e)=>{
3+
const charCode = e.charcode
4+
5+
if( 65<=charCode<=90 || 97<=charCode<=122){
6+
e.preventDefault()
7+
}
8+
9+
})
10+
let buttons = document.querySelectorAll("button");
11+
12+
let string = "";
13+
let arr = Array.from(buttons)
14+
15+
arr.forEach(button =>{
16+
button.addEventListener("click", (e)=>{
17+
if(e.target.innerHTML == '='){
18+
string = eval(string);
19+
input.value = string
20+
}
21+
22+
else if(e.target.innerHTML=="AC"){
23+
string='';
24+
input.value=string;
25+
}
26+
27+
else if(e.target.innerHTML == "DEL"){
28+
string=string.substring(0,string.length-1);
29+
input.value= string;
30+
}
31+
else{
32+
if (/^[\d+*\/%-]$/.test(e.target.innerHTML)) {
33+
string += e.target.innerHTML;
34+
input.value = string;
35+
}
36+
}
37+
})
38+
})
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif;
6+
}
7+
body {
8+
background: linear-gradient(to top, rgb(1, 88, 88), rgb(1, 64, 83));
9+
width: 100%;
10+
height: 100vh;
11+
align-items: center;
12+
justify-content: center;
13+
display: flex;
14+
}
15+
16+
.calc {
17+
background: #222;
18+
box-shadow: inset 0 4px 8px 0 rgba(0, 0, 0, 0.2),
19+
0 6px 20px 0 rgba(0, 0, 0, 0.2);
20+
border-radius: 12px;
21+
padding: 20px;
22+
}
23+
24+
input {
25+
width: 352px;
26+
height: 70px;
27+
border: none;
28+
background: transparent;
29+
margin: 10px;
30+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
31+
padding: 24px;
32+
font-size: 40px;
33+
text-align: right;
34+
cursor: pointer;
35+
color: whitesmoke;
36+
}
37+
38+
input::placeholder {
39+
color: #848282;
40+
}
41+
42+
button {
43+
color: whitesmoke;
44+
background: transparent;
45+
width: 70px;
46+
height: 70px;
47+
border-radius: 16px;
48+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.3), 0 6px 20px 0 rgba(0, 0, 0, 0.2);
49+
border: none;
50+
margin: 10px;
51+
font-weight: bold;
52+
box-sizing: border-box;
53+
cursor: pointer;
54+
font-size: 23px;
55+
}
56+
57+
.equal-btn {
58+
background-color: rgb(223, 147, 5);
59+
color: white;
60+
font-size: 27px;
61+
}
62+
63+
.operator {
64+
color: rgb(245, 189, 4);
65+
}

0 commit comments

Comments
 (0)