-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
75 lines (67 loc) · 2.39 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=1920, initial-scale=1.0">
<title>Debuggers - Vitor Rodrigues</title>
<script src="calculadora.js"></script>
<link rel="stylesheet" href="styles/main.css">
</head>
<body>
<div>
<section>
<header>Calculadora - Utilize somente inteiros</header>
<content>
<p>Digite os números</p>
<div class="area_dados">
x:<input type="text" name="num1" id="num1" type="number" inputmode="numeric"> y:<input type="text" name="num2" id="num2" type="number" inputmode="numeric"> <span id="resultado"></span>
</div>
<div class="area_botoes">
<input type="button" value="Somar" onclick="fazerCalculo('+')">
<input type="button" value="Subtrair" onclick="fazerCalculo('-')">
<input type="button" value="Multiplicar" onclick="fazerCalculo('*')">
<input type="button" value="Dividir" onclick="fazerCalculo('/')">
</div>
</content>
</section>
</div>
Evoluimos para VERSAO 2.0!
</body>
<script>
// Códigos da página
function fazerCalculo(operador) {
let x = lerInteiro("num1")
let y = lerInteiro("num2")
if (isNaN(x) || isNaN(y)) {
escreverResultado("Digite números inteiros para fazer as operações")
return
}
let resultado = calcular(x, y, operador)
escreverResultado("= " + resultado)
}
function calcular(x,y,op) {
switch (op) {
case "+":
return Calculadora.somar(x,y)
case "-":
return Calculadora.subtrair(x,y)
case "*":
return Calculadora.multiplicar(x,y)
case "/":
return Calculadora.dividir(x,y)
}
throw "operação inválida"
}
function escreverResultado(html) {
document.getElementById("resultado").innerHTML = html
}
function lerInteiro(id) {
return parseInt(document.getElementById(id).value)
}
// Executa a função quando a página terminar de carregar
window.onload = function() {
// Coloca foco no elemento da calculadora
document.getElementById("num1").focus()
}
</script>
</html>