forked from cripi-interface-development/dz4-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdz4.html
More file actions
153 lines (150 loc) · 3.32 KB
/
dz4.html
File metadata and controls
153 lines (150 loc) · 3.32 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE HTML SYSTEM>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<title>Калькулятор</title>
<meta charset="utf-8">
<style type="text/css">
.layout {
width: 385px;
height: 505px;
padding: 10px;
background-color: #9ecdce;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.calculator {
width: 380px;
height: 500px;
background-color: #9ecdce;
}
.button_number {
width: 100px;
height: 100px;
background-color: #cce0f5;
text-align: center;
border: 2px black;
border-radius: 50px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
font-size: 30px;
}
.button_operation, .button_equality {
width: 80px;
height: 80px;
background-color: #cce0f5;
text-align: center;
border-radius: 60px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
font-size: 25px;
}
.button_empty{
width: 100px;
height: 100px;
}
.button_number:hover, .button_operation:hover, .button_equality:hover {
background-color: #5eacae;
}
.numbers {
background-color: #9ecdce;
width: 300px;
height: 401px;
float: left;
}
.operations {
background-color: #9ecdce;
width: 80px;
height: 3px;
float: right;
}
.row {
width: 380px;
height: 100px;
font-size: 30px;
background-color: #c4e1e1;
display: inline-block;
float: right;
border-radius: 10px;
}
</style>
</head>
<body>
<div class="layout">
<div class="calculator">
<div class="row"><p id="output"></p></div>
<table class="numbers">
<tr>
<td id="1" class="button_number">1</td><td id="2" class="button_number">2</td><td id="3" class="button_number">3</td>
</tr>
<tr>
<td id="4" class="button_number">4</td><td id="5" class="button_number">5</td><td id="6" class="button_number">6</td>
</tr>
<tr>
<td id="7" class="button_number">7</td><td id="8" class="button_number">8</td><td id="9" class="button_number">9</td>
</tr>
<tr>
<td class="button_empty"></td><td id="0" class="button_number">0</td><td class="button_empty"></td>
</tr>
</table>
<table class="operations">
<tr><td id="+" class="button_operation">+</td></tr>
<tr><td id="-" class="button_operation">-</td></tr>
<tr><td id="*" class="button_operation">*</td></tr>
<tr><td id="/" class="button_operation">/</td></tr>
<tr><td id="=" class="button_equality">=</td></tr>
</table>
</div>
</div>
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
var x = 0;
var op;
var y = 0;
var changed = false;
$('.button_number').click(function(event) {
if (op === undefined)
{
x = x * 10 + parseFloat($(this).attr("id"));
$('#output').text(x);
}
else
{
changed = true;
y = y * 10 + parseFloat($(this).attr("id"));
$('#output').text(x + " " + op + " " + y);
}
});
$('.button_operation').click(function(event) {
op = $(this).attr("id");
$('#output').text(x + " " + op);
});
$('.button_equality').click(function(event) {
if (op !== undefined)
{
var res;
switch(op)
{
case '+': res = x + y;
break;
case '-': res = x - y;
break;
case '*': res = x * y;
break;
case '/': res = x / y;
}
if (changed)
{
$('#output').text(res);
}
else
{
$('#output').text("Wrong Format");
}
x = 0;
y = 0;
op = undefined;
}
});
});
</script>
</body>
</html>