-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjogo_segredo.html
More file actions
65 lines (51 loc) · 1.18 KB
/
Copy pathjogo_segredo.html
File metadata and controls
65 lines (51 loc) · 1.18 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
<!DOCTYPE html>
<meta charset="UTF-8">
<input/>
<button>Tentativa</button>
<script>
function sorteio(){
return Math.round(Math.random() * 10);
}
function sorteiaNumeros(quantidade) {
var segredo = [];
var numero = 1;
while(numero <= quantidade){
var numeroAleatorio = sorteio();
var achou = false;
if(numeroAleatorio !== 0){
for(var posicao = 0; posicao < segredo.length; posicao++){
if(segredo[posicao] == numeroAleatorio){
achou = true;
break;
}
}
if(achou == false){
segredo.push(numeroAleatorio);
numero++;
}
}
}
return segredo;
}
var segredos = sorteiaNumeros(6);
console.log(segredos);
var texto = document.querySelector("input");
texto.focus();
function verifica(){
var achou = false;
for(var posicao = 0; posicao < segredos.length; posicao++){
if(texto.value == segredos[posicao]) {
alert("Você acertou!!");
achou = true;
break;
}
}
if(achou == false){
alert("Você ERROU!!!!!");
}
texto.value = "";
texto.focus();
}
var botao = document.querySelector("button");
botao.onclick = verifica;
</script>