1
-
2
- var mysterious_number = Math . floor ( Math . random ( ) * 10 ) ;
1
+ var mysterious_number = 0 ;
3
2
var attempts = 4 ;
4
3
var found = false ;
5
4
6
- // Resposta do valor para testar: document.getElementById("clue").innerHTML = numero ;
5
+ // Resposta do valor para testar: document.getElementById("clue").innerHTML = mysterious_number ;
7
6
8
- function playGame ( ) {
9
- checkAttempts ( ) ;
7
+ document . querySelector ( 'body' ) . onload = function ( ) {
8
+ var tex = ".: REGRAS :<br>" +
9
+ "1. O jogo de adivinhação onde o valor será algum valor de 0 a 9. <br/>" +
10
+ "2. Você possui apenas 4 tentativas para descobrir. <br/>" +
11
+ "3. Após acertar o número a ser descorberto, o jogo será reiniciado. <br/>" +
12
+ "4. Após as 4 tentativas e você não conseguir descobrir, o jogo se reinicia." ;
13
+
14
+ swal ( {
15
+ title : 'Seja Bem Vindo!' ,
16
+ type : 'info' ,
17
+ html : tex
18
+ } ) ;
10
19
}
11
20
21
+
22
+ document . querySelector ( 'button.btnSubmit' ) . onclick = function ( ) {
23
+ mysterious_number = Math . floor ( Math . random ( ) * 10 ) ;
24
+
25
+ checkAttempts ( ) ;
26
+ }
27
+
12
28
function getValue ( ) {
13
29
var num = document . getElementById ( "value" ) . value ;
14
30
return num ;
@@ -18,10 +34,17 @@ function setMessage(text){
18
34
document . getElementById ( "clue" ) . innerHTML = text ;
19
35
}
20
36
37
+ function showSucessMessage ( ) {
38
+ swal ( {
39
+ title : 'Você Acertou!' ,
40
+ type : 'success' ,
41
+ html : "Parabéns você acertou! O Jogo será reiniciado"
42
+ } ) ;
43
+ }
21
44
22
45
function checkItsDone ( ) {
23
46
if ( getValue ( ) == mysterious_number ) {
24
- setMessage ( "--> Parabéns você acertou! O Jogo será reiniciado" ) ;
47
+ showSucessMessage ( ) ;
25
48
found = true ;
26
49
27
50
restart ( ) ;
@@ -78,7 +101,7 @@ function checkNumberAttempts(cont){
78
101
}
79
102
80
103
function restart ( ) {
81
- mysterious_number = Math . floor ( Math . random ( ) * 10 ) ;
82
- attempts = 4 ;
83
- document . getElementById ( "value" ) . value = "" ;
104
+ var mysterious_number = Math . floor ( Math . random ( ) * 10 ) ;
105
+ var attempts = 4 ;
106
+ var found = false ;
84
107
}
0 commit comments