-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (60 loc) · 2.13 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
<!DOCTYPE html>
<html>
<head>
<title>calculate</title>
<meta charset="SimpleCalculator">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<style>
#Error,
#Error1 {
display: none;
color: red;
}
</style>
<input type="text" id="n1" onchange="checkInput(this, -1000000, 1000000, 'Error')">
<p id="Error">לא תקין</p>
<input type="text" id="n2" onchange="checkInput(this, -1000000, 1000000, 'Error1')">
<p id="Error1">לא תקין</p>
<select id="operators">
<option value="+">+</option>
<option value="-">-</option>
<option value="/">/</option>
<option value=""></option>
</select>
<button onclick="calc();">=</button>
<input type="text" id="result" />
<script>
function checkInput(element, number1, number2, errorElement) {
let error = document.getElementById(errorElement);
if (element.value > number1 && element.value < number2) {
element.style.border = '1px solid green'
error.style.display = 'none'
return true
} else if (element.value != number1 && element.value != number2) {
element.style.border = '1px solid red'
error.style.display = 'block'
return false
}
}
function calc() {
var n1 = parseFloat(document.getElementById('n1').value);
var n2 = parseFloat(document.getElementById('n2').value);
var oper = document.getElementById('operators').value;
if (oper === '+') {
document.getElementById('result').value = n1 + n2;
}
if (oper === '-') {
document.getElementById('result').value = n1 - n2;
}
if (oper === '/') {
document.getElementById('result').value = n1 / n2;
}
if (oper === '*') {
document.getElementById('result').value = n1 * n2;
}
}
</script>
</body>
</html>