Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
98 lines (85 loc) · 1.92 KB
/
Copy pathtest.js
File metadata and controls
98 lines (85 loc) · 1.92 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
var cards = [
{
rank: "queen",
suit: "hearts",
cardImage:"images/queen-of-hearts.png"
},
{
rank: "queen",
suit: "diamonds",
cardImage:"images/queen-of-diamonds.png"
},
{
rank: "king",
suit: "hearts",
cardImage:"images/king-of-hearts.png"
},
{
rank: "king",
suit: "diamonds",
cardImage:"images/king-of-diamonds.png"
}
];
var cardsInPlay = [];
var checkForMatch = function()
{
if (cardsInPlay[0] == cardsInPlay[1])
{
alert("You found a match!");
}
else
{
alert("Sorry, try again.");
}
};
var flipCard = function(cardId)
//flips the card that was selected
{
cardId =
document.getElementsByTagName('img');
console.log(cardId);
console.log("User flipped " + cards[cardId]);
// cardsInPlay.push(cards[cardId].rank);
console.log(this.cards[cardId].cardImage);
console.log(this.cards[cardId].suit);
// this.setAttribute(cards[cardId].cardImage, src);
if (cardsInPlay.length === 2 )
{
checkForMatch();
}
else{};
}
var createBoard = function(){
for (var i = 0; i < cards.length; i++)
{
var newListItem = document.createElement('img');
newListItem.setAttribute('src', 'images/back.png');
newListItem.setAttribute('cardId', i );
// console.log(newListItem);
var board = document.getElementById("game-board");
board.appendChild(newListItem);
};
document.addEventListener("click", function(){
cardsInPlay.push(newListItem);
console.log(cardsInPlay);
flipCard(newListItem);
})
};
createBoard();
//if cardsInPlay[0] == cardsInPlay[1] then stay flipped
//else flip()
// {
// new img src= ...
// }
/*var flip = function(num)
{
}
console.log("User flipped" + cardOne);
console.log("User flipped" + cardFour);
/when we click an image
//document.getElementsByClassName('queen').on('click', function()
{
//console log something
console.log("User flipped queen");
flip(cards[x])
})*/