-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarot.js
102 lines (69 loc) · 2.42 KB
/
tarot.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
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
99
100
101
const tarotCardDesc= [ {
src: 'card-0.jpg',
desc: 'This is the Queen of Cups tarot card'
},
{src: 'card-1.jpg',
desc: 'This is the Fool tarot card'
},
{src: 'card-2.jpg',
desc: 'This is the Star tarot card'
},
{src: 'card-3.jpg',
desc: 'This is the Hanged Man tarot card'
} ];
/* console.log(tarotCard[3]);
//creates a random number between 0 and 1
const index = Math.random();
console.log(index);*/
function pickRandomCard1() {
const index = Math.random();
const max = 4;
const min = 0;
const cardNumber = Math.floor (index * (max - min ) + min);
return cardNumber;
}
//console.log("randomCard", pickRandomCard1());
function drawACard() {
console.log(pickRandomCard1());
const pickRandomCard = pickRandomCard1();
const img = document.querySelector(".picked-card img");
//calling random card
img.src = `card-${pickRandomCard}.jpg`;
const container = document.querySelector(".picked-card");
//adding something to the class list
container.classList.add("show");
console.log(img.src);
console.log(tarotCardDesc[pickRandomCard]);
const hide = document.querySelector(".card-description");
hide.classList.remove("hide");
const cardDescription = document.querySelector(".card-description")
//it will pick a random card but also show the accompanying description
cardDescription.innerHTML = tarotCardDesc[pickRandomCard].desc;
console.log(cardDescription);
}
function shuffleCard() {
const container = document.querySelector(".picked-card");
container.classList.remove("show");
const hide = document.querySelector(".card-description");
hide.classList.add("hide");
}
// this is the max and min numbers we can call
//const max = 77;
//const min = 0;
//math floor gets rid of the decimal
//const cardNumber = Math.floor (index * (max - min ) + min);
//console.log("cardNumber", cardNumber);
// if statements that round up or below depending on the statements below
/*if(index >= 0 && index <= 0.25) {
console.log(tarotCard[0]);
}
if(index > 0.25 && index <= 0.5) {
console.log(tarotCard[1]);
}
if(index > 0.50 && index <= 0.75) {
console.log(tarotCard[2]);
}
if(index > 0.75 && index <= 1) {
console.log(tarotCard[3]);
}
console.log(Math.random());*/