-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
110 lines (74 loc) · 2.88 KB
/
script.js
File metadata and controls
110 lines (74 loc) · 2.88 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
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
let answers = [
"frontend", "fullstack", "backend", "javascript",
"typescript", "game", "software", "developer", "web",
"google", "styles", "design", "html", "hardware",
"bootstrap", "reactnative", "vscode", "flutter", "index"];
let word = answers[Math.floor(Math.random() * answers.length)];
let chances = 6;
let hits = 0;
let img = 0;
let position;
for (position = 0; position < word.length; position++){
let span = document.createElement("span");
span.setAttribute('id', position);
let div = document.getElementById("word");
div.appendChild(span);
}
let alfabeto = "abcdefghijklmnopqrstuvwxyz";
let letters = alfabeto.split("");
for (position = 0; position < letters.length; position++){
let button = document.createElement("button");
let letter = document.createTextNode(letters[position]);
button.appendChild(letter);
button.setAttribute('onclick', 'choice(\''+letters[position]+'\')');
button.setAttribute('id', letters[position]);
let div = document.getElementById("letters");
div.appendChild(button);
}
function choice(letter) {
let right = false;
for (position = 0; position < word.length; position++){
if (letter === word[position]){
let span = document.getElementById(position);
let l = document.createTextNode(letter);
span.appendChild(l);
let button = document.getElementById(letter);
button.setAttribute('class', 'check');
button.removeAttribute('onclick');
hits++;
right = true;
}
}
if(right === false){
img++;
document.getElementById("forca").src = "img/forca"+img+".png";
let button = document.getElementById(letter);
button.setAttribute('class', 'wrong');
button.removeAttribute('onclick');
chances--;
}
if (chances === 0) {
let msg = document.createElement("p");
document.getElementById("forca").src = "img/go.png"
let button = document.createElement("button");
let t2 = document.createTextNode("Jogar Novamente")
button.appendChild(t2);
button.setAttribute('class', 'new-bt');
button.setAttribute('onclick', 'window.location.reload()');
let div = document.getElementById("new");
div.appendChild(msg);
div.appendChild(button);
}
if (hits === word.length) {
let msg = document.createElement("p");
document.getElementById("forca").src = "img/win.png"
let button = document.createElement("button");
let t2 = document.createTextNode("Jogar Novamente")
button.appendChild(t2);
button.setAttribute('class', 'new-bt');
button.setAttribute('onclick', 'window.location.reload()');
let div = document.getElementById("new");
div.appendChild(msg);
div.appendChild(button);
}
}