-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
126 lines (123 loc) · 4.52 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculadora</title>
<style>
* {
margin: 0;
padding: 0;
font-family: "Poppins", sans-serif;
}
.Fundo {
background-image: linear-gradient(45deg, black, purple);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
color: whitesmoke;
}
.Calculadora {
background-color: rgba(0, 0, 0, 0.745);
border-radius: 10px;
padding: 20px;
text-align: center;
}
.btn {
height: 40px;
width: 40px;
font-size: large;
cursor: pointer;
margin: 5px;
background-color: rgb(31, 31, 31);
border: none;
color: whitesmoke;
}
.btn:hover {
background-color: crimson;
}
.btn:active {
background-color: darkred;
}
#resultado {
width: 204.9px;
height: 40px;
background-color: rgb(98, 101, 103);
color: rgb(236, 240, 241);
text-align: right;
font-size: larger;
padding: 5px;
margin: 0 auto 10px auto;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="Fundo">
<h1>by necr0nomic0n</h1>
<div class="Calculadora">
<p id="resultado"></p>
<table>
<tr>
<td><button class="btn" onclick="clean()">C</button></td>
<td><button class="btn" onclick="back()"><-</button></td>
<td><button class="btn" onclick="insert('/')">/</button></td>
<td><button class="btn" onclick="insert('*')">*</button></td>
</tr>
<tr>
<td><button class="btn" onclick="insert('7')">7</button></td>
<td><button class="btn" onclick="insert('8')">8</button></td>
<td><button class="btn" onclick="insert('9')">9</button></td>
<td><button class="btn" onclick="insert('-')">-</button></td>
</tr>
<tr>
<td><button class="btn" onclick="insert('4')">4</button></td>
<td><button class="btn" onclick="insert('5')">5</button></td>
<td><button class="btn" onclick="insert('6')">6</button></td>
<td><button class="btn" onclick="insert('+')">+</button></td>
</tr>
<tr>
<td><button class="btn" onclick="insert('1')">1</button></td>
<td><button class="btn" onclick="insert('2')">2</button></td>
<td><button class="btn" onclick="insert('3')">3</button></td>
<td rowspan="2"><button class="btn" style="height: 100px;" onclick="calcular()">=</button></td>
</tr>
<tr>
<td colspan="2"><button class="btn" style="width: 100px;" onclick="insert('0')">0</button></td>
<td><button class="btn" onclick="insert('.')">.</button></td>
</tr>
</table>
</div>
</div>
<script>
function insert(num) {
const resultado = document.getElementById('resultado');
resultado.innerHTML += num;
}
function clean() {
document.getElementById('resultado').innerHTML = "";
}
function back() {
const resultado = document.getElementById('resultado').innerHTML;
document.getElementById('resultado').innerHTML = resultado.slice(0, -1);
}
function calcular() {
const resultado = document.getElementById('resultado').innerHTML;
try {
if (resultado) {
if (resultado.includes('/0')) {
throw new Error("Cannot divide by zero");
}
document.getElementById('resultado').innerHTML = eval(resultado.replace(/x/g, '*'));
} else {
document.getElementById('resultado').innerHTML = "Tem nada aqui";
}
} catch (e) {
document.getElementById('resultado').innerHTML = "Erro";
}
}
</script>
</body>
</html>