forked from mbaezpy/trentose-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (36 loc) · 1007 Bytes
/
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
/* your code should go here */
// 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 counter = 1;
$(document).ready(function () {
var cards = $('.cards').children();
var shuffleData = generateData(10);
initializeGame(cards, shuffleData);
$(cards).click(function () {
var id = $(this).attr('id');
if (shuffleData[id] == counter) {
$(this).attr('class', 'done');
counter++;
if(counter == 11) {
alert('you win');
initializeGame(cards, shuffleData);
}
} else {
alert('you lose');
}
});
$('.opt-start').click(function() {
$(cards).attr('class', 'hidden');
counter = 1;
})
});
function initializeGame(cards, shuffleData) {
counter = 1;
$(cards).each( function(index) {
var id = $(this).attr('id');
var text = $(this).find('h3');
$(text).text(shuffleData[id]);
$(this).attr('class', 'done');
});
}