-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
112 lines (108 loc) · 2.97 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#head{
color: teal;
text-align: center;
margin-top: 50px;
font-size: 38px;
}
#main{
width: 23%;
border: 1px solid transparent;
margin: auto;
border-radius: 10px;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
#disply{
width: 75%;
height: 40px;
margin: auto;
margin-top: 40px;
border-radius: 10px;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
}
#keys{
width: 75%;
display: grid;
grid-template-columns: repeat(4,1fr);
grid-template-rows: repeat(4,1fr);
gap: 10px;
margin: auto;
margin-top: 10px;
margin-bottom: 40px;
}
#keys>div{
display: flex;
justify-content: center;
align-items: center;
font-weight: bold;
padding: 10px;
font-size: 20px;
border-radius: 10px;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
.black{
background-color: black;
color: white;
}
.red{
background-color: red;
color: white;
}
</style>
</head>
<body>
<h1 id="head">My Calculator</h1>
<div id="main">
<div id="disply"></div>
<div id="keys">
<div>1</div>
<div>2</div>
<div>3</div>
<div class="black">+</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div class="black">-</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div class="black">*</div>
<div class="red">c</div>
<div>0</div>
<div class="black">=</div>
<div class="black">/</div>
</div>
</div>
</div>
</body>
</html>
<script>
let key=document.querySelectorAll("#keys>div");
let bag="";
for(let i=0;i<key.length;i++){
key[i].addEventListener("click" ,masaicalculator)
}
function masaicalculator(event){
let targetnum=event.target.innerText;
if(targetnum==("c")){
bag=""
document.querySelector("#disply").innerText=""
}else if(targetnum == ("=")){
document.querySelector("#disply").innerText=eval(bag)
}else{
bag=bag+targetnum;
document.querySelector("#disply").innerText=bag
}
}
</script>