-
Notifications
You must be signed in to change notification settings - Fork 0
/
Soma.html
80 lines (61 loc) · 2.01 KB
/
Soma.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
<!DOCTYPE html>
<html>
<!--Background-Animado-->
<div class="context"></div>
<div class="area" >
<ul class="circles">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<head>
<title>Soma</title>
<!--Link-Alerta-->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="Soma.css">
<meta charset="UTF-8"/>
</head>
<!--Cabeçalho-->
<header>Adição</header>
<body>
<div class="box"></div>
<input class="Campo-de-Resposta" type="text" id="valor"/>
<h1 class="Conta-Soma" id="display">2 + 3</h1>
<script type="text/javascript">
function numeroAleatorio() {
return Math.floor(Math.random() * 1000);
}
let numero1 = numeroAleatorio();
let numero2 = numeroAleatorio();
let display = document.querySelector("#display");
display.innerHTML = numero1 + " + " + numero2;
let input = document.querySelector("#valor");
input.addEventListener("keyup", (event) => {
if (event.keyCode == "13") {
if (numero1 + numero2 === parseInt(input.value)) {
numero1 = numeroAleatorio();
numero2 = numeroAleatorio();
display.innerHTML = numero1 + " + " + numero2;
input.value = "";
} else {
swal("Você errou, o valor correto é: " + (numero1 + numero2));
}
}
});
</script>
<nav>
<ul class="voltar">
<li><a href="Intro.html">Voltar</a></li>
</ul>
</nav>
</body>
<footer>Colégio Estadual São José</footer>
</html>