-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (120 loc) · 3.4 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
113
114
115
116
117
118
119
120
121
122
<!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">
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="./utile.css">
<title>Calculator</title>
</head>
<body>
<div id="mainid" >
<h1 class="text-center">Calculator</h1>
<div class="cantainer">
<div class="row">
<input type="text" class="input">
</div>
<div class="row">
<button class="button" style="background-color: floralwhite; width: 145px; " >AC</button>
<!-- <button class="button">+/-</button> -->
<button class="button">%</button>
<button class="button">/</button>
</div>
<div class="row">
<button class="button">7</button>
<button class="button">8</button>
<button class="button">9</button>
<button class="button">*</button>
</div>
<div class="row">
<button class="button">4</button>
<button class="button">5</button>
<button class="button">6</button>
<button class="button">-</button>
</div>
<div class="row">
<button class="button">1</button>
<button class="button">2</button>
<button class="button">3</button>
<button class="button">+</button>
</div>
<div class="row">
<button class="button">0</button>
<!-- <button class="button">0</button> -->
<button class="button" style="font-size: 35px;" >.</button>
<button class="button" style="width: 145px; background-color: lightcyan;" >=</button>
</div>
</div>
</div>
</body>
<style>
*{
margin: 0;
padding: 0;
}
.text-center{
/* text-decoration: underline; */
font-family: cursive, Arial,sans-serif;
font-style: oblique;
font-size: xx-large;
text-align: center;
}
#mainid{
margin: 100px;
}
.cantainer{
text-align: center;
margin: auto;
display: flex;
flex-direction: column;
}
.button{
font-family: 'math', 'Arial Narrow', Arial, sans-serif;
width: 70px;
/* padding: 20px; */
margin: 0 3px;
border: 2px solid black;
border-radius: 9px;
/* max-height: 7px; */
height: 50px;
font-size: 25px;
}
.row{
display: flex;
margin: 8px 0;
align-items: center;
justify-content: center;
}
.input{
width: 300px;
font-size: 20px;
margin: 0;
padding: 10px 2px;
border: 2px solid black;
border-radius: 5px; ;
}
</style>
<script>
let string = "";
let buttons = document.querySelectorAll('.button');
Array.from(buttons).forEach((button)=>{
button.addEventListener('click', (e)=>{
if(e.target.innerHTML == "="){
string = eval(string);
document.querySelector('input').value = string;
}
else if(e.target.innerHTML == "AC"){
string = ""
document.querySelector('input').value = string;
}
else{
console.log(e.target)
string = string + e.target.innerHTML;
document.querySelector('input').value = string;
}
})
})
</script>
<script src="script.js"></script>
</html>