forked from mbaezpy/trentose2015-midterm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
74 lines (60 loc) · 1.88 KB
/
app.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
/* your code should go in this file */
/*
* The data is available in the array *data*
* Each element of the array has the following structure:
* {
* word_en : "Apple", // word in english
* word_de : "Apfel" // word in german
* }
*/
var correctAnswers = 0;
$(document).ready(function(){
initGame();
var index = 0;
nextWord(index);
$(".current").click(function(){
$(".word").addClass("hidden");
$(".solution").removeClass("hidden");
$(".options").removeClass("hidden");
});
$(".opt-correct").click(function(){
correctAnswers++;
});
$(".btn").click(function(){
// $(this).hasClass("opt-")
index++;
if(index < data.length)
nextWord(index);
else
endGame();
});
});
function initGame(){
if(data.length == 0)
endGame();
var tmpl = ' <li id="ID" class = "current">' +
' <h3 class = "word">WORD</h3>' +
' <h3 class="solution hidden">SOLUTION</h3>'+
' </li> ';
$(".cards").empty();
$(".options").removeClass("hidden").addClass("hidden");
var index = 0;
var card = tmpl.replace("ID", index);
card = card.replace("WORD", data[index].word_en);
card = card.replace("SOLUTION", data[index].word_de);
$(".cards").append(card);
}
function nextWord(index){
$(".options").removeClass("hidden").addClass("hidden");
$(".word").text(data[index].word_en);
$(".word").removeClass("hidden");
$(".solution").text(data[index].word_de);
$(".solution").removeClass("hidden").addClass("hidden");
$(".current").attr("id", index);
}
function endGame(){
$(".practice").addClass("hidden");
$("#tot-good").text(correctAnswers);
$("#tot").text(data.length);
$(".final").removeClass("hidden");
}