-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalci.html
132 lines (124 loc) · 3.48 KB
/
calci.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!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>CALCULATOR</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
body{
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(45deg, black , rgb(95, 94, 94));
}
.calculator{
border: 2px solid rgb(57, 56, 56);
padding: 18px;
height: 95%;
border-radius: 14px;
background-color: transparent;
box-shadow: 0px 3px 15px grey;
}
input{
width: 300px;
border: none;
padding: 24px;
margin: 10px;
background: transparent;
text-align: right;
font-size: 30px;
cursor: pointer;
color: white;
}
input::placeholder{
columns: white;
}
button{
width: 60px;
height:50px;
margin: 10px;
border-radius: 50%;
background: transparent;
color: white;
font-size: 18px;
cursor: pointer;
}
.equlabtn{
background-color: #fb7c14;
}
.operator{
color: #fb7c14;
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" placeholder="0" id="inputbox">
<div>
<button class="operator">AC</button>
<button class="operator">DEL</button>
<button class="operator">%</button>
<button class="operator">/</button>
</div>
<div>
<button>7</button>
<button>8</button>
<button>9</button>
<button class="operator">*</button>
</div>
<div>
<button>4</button>
<button>5</button>
<button>6</button>
<button class="operator">-</button>
</div>
<div>
<button>1</button>
<button>2</button>
<button>3</button>
<button class="operator">+</button>
</div>
<div>
<button>00</button>
<button>0</button>
<button>.</button>
<button class="equlabtn">=</button>
</div>
</div>
<script>
let input=document.getElementById('inputbox')
let buttons= document.querySelectorAll('button')
let string= ""
let arr= Array.from(buttons)
arr.forEach(button => {
button.addEventListener('click' ,(e)=>{
if(e.target.innerHTML == '='){
string= eval(string)
input.value= string
}
else if(e.target.innerHTML== 'AC'){
string=""
input.value=string
}
else if(e.target.innerHTML== 'DEL'){
string= string.substring(0, string.length - 1)
input.value=string
}
else{
string+= e.target.innerHTML
input.value= string
}
})
})
</script>
</body>
</html>