-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
73 lines (56 loc) · 2.17 KB
/
script.js
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
// words
var word_list = ["BURGUESÍA", "ALBAÑIL", "CAMPESINOS", "OBREROS", "REY",
"REINA","BRÚJULA", "AZTECAS", "MAYAS", "INCAS", "MAPUCHE", "RANQUEL",
"MEDITERRÁNEO", "MONARQUÍA", "REVOLUCIÓN", "INDUSTRIAL", "FRANCIA","INGLATERRA", "EUROPA",
"ABSOLUTISMO", "CAPITALISMO", "PODER", "CAMBIO", "CONTINUIDAD",
"HISTORIA", "COLONIZACIÓN", "CONQUISTA", "ECONOMÍA", "TRABAJO",
"ESTADO", "PRODUCCIÓN", "PLUSVALÍA", "EXPLOTACIÓN", "VAPOR",
"GENOCIDIO", "FEUDAL", "PROPIEDAD", "COMUNAL", "ESCLAVO", "FÁBRICA"];
var match_words = 0;
var timer, index;
var tiempo = 59;
function startGame(){
document.getElementById("start").style.display = "none";
document.getElementById("game").style.display = "block";
document.getElementById("final").style.display = "none";
//cursor on input
document.getElementById("typed_word").focus();
//load words
loadWord();
// cada 1segundo se llama la funcion restartTime()
timer = setInterval('restartTime()', 1000);
}
function loadWord(){
// posicion de forma aleatoria
index = Math.round(Math.random()*(word_list.length-1));
document.getElementById("word").innerHTML = word_list[index];
//delete position showed
word_list.splice(index,1);
}
function compare(){
var show_word = document.getElementById("word").innerHTML;
var word_typed = document.getElementById("typed_word").value;
word_typed = word_typed.toUpperCase();
if(show_word == word_typed){
match_words++;
document.getElementById("typed_word").value="";
addNode(word_typed);
loadWord(); //load another word
}
}
function addNode(word){
var span = document.createElement('span');
span.innerHTML = word;
document.getElementById("register").appendChild(span);
}
function restartTime(){
tiempo--;
document.getElementById("time").innerHTML = tiempo;
if(tiempo == 0){
clearInterval(timer);
document.getElementById('typed_word').readOnly = true;
document.getElementById("time").style.display = "block";
document.getElementById("final").style.display = "block";
document.getElementById("total").innerHTML = match_words;
}
}