-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
138 lines (116 loc) · 3.34 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width = device-width, initial-scale = 1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Calculator</title>
</head>
<style>
body {
background-color: #374046;
user-select: none;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: 4px;
background-color: #BDBDBD;
padding: 5px;
border-radius: 5px;
max-width: 360px;
font-family: Tahoma, sans-serif;
}
.item {
background-color: #03A9F4;
color: #212121;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
font-size: 22px;
font-weight: bold;
cursor: pointer;
}
form {
max-width: 100%;
}
input {
width: 100%;
height: 60px;
border: none;
font-size: 30px;
outline: none;
text-align: right;
}
.input {
grid-column: 1/-1;
padding: 0;
}
.clean {
grid-column: 1/3;
background-color: #0288D1;
}
.back {
grid-column: 3/-1;
}
.equal {
grid-column: 4;
grid-row: 6/8;
background-color: #0288D1;
}
.zero {
grid-column: 1/3;
}
.item:hover {
background-color: #CDDC39;
}
</style>
<body>
<div class="container">
<div class="item input">
<form name="form">
<input type="text" name="textview" readonly>
</form>
</div>
<div class="item clean" onclick="clean()">C</div>
<div class="item back" onclick="back()">←</div>
<div class="item" onclick="insert('+')">+</div>
<div class="item" onclick="insert('-')">-</div>
<div class="item" onclick="insert('*')">×</div>
<div class="item" onclick="insert('/')">÷</div>
<div class="item" onclick="insert('7')">7</div>
<div class="item" onclick="insert('8')">8</div>
<div class="item" onclick="insert('9')">9</div>
<div class="item" onclick="insert('(')">(</div>
<div class="item" onclick="insert('4')">4</div>
<div class="item" onclick="insert('5')">5</div>
<div class="item" onclick="insert('6')">6</div>
<div class="item" onclick="insert(')')">)</div>
<div class="item" onclick="insert('1')">1</div>
<div class="item" onclick="insert('2')">2</div>
<div class="item" onclick="insert('3')">3</div>
<div class="item equal" onclick="equal()">=</div>
<div class="item zero" onclick="insert('0')">0</div>
<div class="item" onclick="insert('.')">.</div>
</div>
<script>
function insert(num) {
document.form.textview.value = document.form.textview.value + num;
}
function clean() {
document.form.textview.value = "";
}
function back() {
let exp = document.form.textview.value;
document.form.textview.value = exp.substring(0, exp.length - 1);
}
function equal() {
let exp = document.form.textview.value;
if (exp) {
document.form.textview.value = eval(exp);
}
}
</script>
</body>
</html>