forked from mbaezpy/trentose-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (37 loc) · 1.13 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
/* your code should go here */
var tmpl = '<li id="ID">'+
'<h3>NUMBER</h3>'+
'</li>';
// Three main classes of cards:
// done: when the user has discovered the pair of cards
// hidden: when the card has not been discovered yet
var count = 1;
function reset() {
$(".cards li").removeClass("hidden");
$(".cards li").removeClass("done");
}
$(document).ready(function(){
for (var i=0; i<data.length; i++) {
$(".cards").append(tmpl.replace("ID",i).replace("NUMBER",data[i]));
}
$(".options .opt-start").on("click", function() {
reset();
$(".cards li").addClass("hidden");
});
$(".cards li").on("click", function(event) {
if ($(this).hasClass("hidden")) {
if ($(this).text() == count) {
$(this).removeClass("hidden");
$(this).addClass("done");
count++;
} else {
$(".cards li").removeClass("hidden");
alert("You lost!");
count = 1;
}
}
if (count == (data.length+1)) {
alert("You won!");
}
});
});