-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
168 lines (138 loc) · 4.54 KB
/
script.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* Data to Show*/
const data = [
// https://kidadl.com/articles/best-kermit-the-frog-quotes-that-muppets-fan-will-love
{
quote: `“Changes happen as time passes by. Soon enough, you'll be grown.”`,
emoji: '🕰️',
image: `url(assets/KermitDriving.jpg)`
},
{
quote: `“I've got a dream too, but it's about singing and dancing and making people happy.”`,
emoji: '🕺 💃',
image: `url(assets/KermitPoint.png)`
},
{
quote: `“Always be yourself. Never take yourself too seriously.”`,
emoji: '😊',
image: `url(assets/KermitBench.jpg)`
},
{
quote: `“I believe creativity is an inherent part of everyone.”`,
emoji: '🖼️',
image: `url(assets/KermitDesk.jpg)`
},
{
quote: `“Life's like a movie. Write your own ending.”`,
emoji: '📽️',
image: `url(assets/KermitStairs.jpg)`
},
{
quote: `“Just because you haven't found your talent yet doesn't mean you don't have one.”`,
emoji: '✨',
image: `url(assets/KermitTea.jpg)`
}
];
/*
Quote and Emoji
*/
// blockquote
const quote = document.querySelector('blockquote');
// emoji
const emoji = document.querySelector('p');
// background
const bgImage = document.querySelector('body');
// Check-Check: change text
quote.innerHTML = "Quotes from Kermit the frog";
// Check-Check: change emoji text
emoji.innerHTML = "😁";
// Check-Check: background image
bgImage.style.backgroundImage= 'url(assets/KermitHat.gif)';
/*
* Navigate to Items with Event Listeners
* Track Number of Items
*/
// initialize item number
let itemNumber = 0;
// get next button
const nextButton = document.querySelector("button.next");
// get previous button
const prevButton = document.querySelector("button.prev");
// get random button
const randButton = document.querySelector("button.random");
// listen for clicks on next button
nextButton.addEventListener("click", function () {
// update, then increase item number with each click
itemNumber = itemNumber + 1;
// if at LAST item
if ( itemNumber > data.length -1 ) {
// reset counting to first item
itemNumber = 0;
}
// display data based on array index
quote.innerHTML = data[itemNumber].quote;
emoji.innerHTML = data[itemNumber].emoji;
bgImage.style.backgroundImage = data[itemNumber].image;
});
// listen for clicks on previous button
prevButton.addEventListener("click", function () {
// update, then DEcrease item number with each click
itemNumber = itemNumber - 1;
// if at FIRST item
if ( itemNumber < 0 ) {
// reset counting to last item
itemNumber = data.length -1;
}
// display data based on array index
quote.innerHTML = data[itemNumber].quote;
emoji.innerHTML = data[itemNumber].emoji;
bgImage.style.backgroundImage = data[itemNumber].image;
});
// listen for clicks on random button
randButton.addEventListener('click', function() {
// generate random number, for total number, of items (data)
randomNumber = Math.floor ( Math.random() * data.length );
// display data based random number
quote.innerHTML = data[randomNumber].quote;
emoji.innerHTML = data[randomNumber].emoji;
bgImage.style.backgroundImage = data[randomNumber].image;
});
// listen for keypress next
document.addEventListener('keyup', function(){
// Next Right Arrow
if ( event.keyCode === 39 ) {
// update, then increase item number with each click
itemNumber = itemNumber + 1;
// if at LAST item
if ( itemNumber > data.length -1 ) {
// reset counting to first item
itemNumber = 0;
}
// display data based on array index
quote.innerHTML = data[itemNumber].quote;
emoji.innerHTML = data[itemNumber].emoji;
bgImage.style.backgroundImage = data[itemNumber].image;
}
// Prev Left Arrow
if ( event.keyCode === 37 ) {
// update, then DEcrease item number with each click
itemNumber = itemNumber - 1;
// if at FIRST item
if ( itemNumber < 0 ) {
// reset counting to last item
itemNumber = data.length -1;
}
// display data based on array index
quote.innerHTML = data[itemNumber].quote;
emoji.innerHTML = data[itemNumber].emoji;
bgImage.style.backgroundImage = data[itemNumber].image;
}
// Random Spacebar
if ( event.keyCode === 32) {
// generate random number, for total number, of items (data)
randomNumber = Math.floor ( Math.random() * data.length );
// display data based random number
quote.innerHTML = data[randomNumber].quote;
emoji.innerHTML = data[randomNumber].emoji;
bgImage.style.backgroundImage = data[randomNumber].image;
}
});