-
Notifications
You must be signed in to change notification settings - Fork 0
/
laugh-factory-script.js
204 lines (143 loc) · 5.85 KB
/
laugh-factory-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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// FUNCTIONS
//Query String CODE
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function startJokes(bgImage, jokesList) {
$("#startJokesBtn").click(function(){
$(".mySlides").addClass(bgImage);
$(".joke").html(jokesList[0]);
});
}
function nextJoke(color, fruitFact, bgImage, jokesList) {
$(".next").click(function(){
if (count < (jokesList.length - 2) ) {
count += 2;
$(".joke").html(jokesList[count]);
}else {
currentSlide(3);
$("#fruitFactTitle").addClass(color);
$("#fruityFact").html(fruitFact);
$(".mySlides").addClass(bgImage);
}
});
}
function prevJoke(jokesList) {
$(".prev").click(function(){
if (count > 1) {
count -= 2;
$(".joke").html(jokesList[count]);
}
});
}
function resetJokes(removeClass, jokesList) {
$("#jokesAgainBtn").click(function(){
count = 0;
$("#fruitFactTitle").removeClass();
$("#fruityFact").html();
$(".mySlides").removeClass(removeClass);
$(".joke").html(jokesList[count]);
});
}
// Jokes are on the even indexes starting at zero
// Punchlines fall on the odd indexes
var orangeJokes = [
"Why did the orange stop in the middle of the road?", "Because it ran out of juice!",
"What school subject is the fruitiest?", "History because it's full of dates!",
"What is a vampire\'s favorite fruit?", "A neck-tarine!",
"When do you go on red and stop at green?", "When you\'re eating a watermelon",
"What do you call an orange that plays the trumpet?","A tooty fruity",
"What are twins\' favorite fruit?", "Pears.",
"Why do oranges wear suntan lotion?", "Because they peel.",
"What kind of fruit can fix your sink?", "A PLUM-ber"
]
var orangeFruitFact = "Not all oranges are orange";
var appleJokes = [
"What did the apple tree say to the hungry caterpillar?", "Leaf me alone.",
"What kind of apple isn\'t an apple?", "A pineapple!",
"What did the apple tree say to the farmer?", "Stop picking on me.",
"What can a whole apple do that half an apple can\'t do?", "It can look round!",
"What did the apple skin say to the apple?", "I\'ve got you covered!",
"What\'s red and goes up and down?", "An apple in an elevator!",
"Why did the apple go to the doctor?", "It felt rotten to the core.",
"Why was the apple alone with the orange?", "Because the banana split."
]
var appleFruitFact = "Apples float in water because they are 25% air.";
var strawberryBananaJokes = [
"Why did the banana go to the doctor?", "Because it wasn\'t peeling well.",
"What kind of shoes are made from banana peels?", "Slippers.",
"Why was the baby strawberry sad?", "Because its mom was in a jam.",
"What key opens a banana?", "A mon-key.",
"Why aren\'t bananas ever lonely?", "Because they come in bunches!",
"What do you call a sad strawberry?", "A blueberry.",
"What do you call a banana that likes to dance?", "A banana shake!",
"What is a ghost\'s favorite fruit?", "A Boo-nana."
]
var strawBanFruitFact = "A strawberry is not an actual berry, but a banana is.";
// SLIDE SHOW CODE
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
// END OF SLIDE SHOW CODE
var count = 0;
var play = getParameterByName('play');
$(".prev, .next").click(function(){
$(".answerBtn").html("SEE ANSWER <img id='answerBtnArrow' src='img/seeAnswerBtn.png'/>");
});
// ORANGE SECTION
if (play == 'orange') {
startJokes("orangeBg", orangeJokes);
nextJoke("orange", orangeFruitFact, "orangeImg", orangeJokes);
prevJoke(orangeJokes);
resetJokes("orangeImg", orangeJokes);
$(".answerBtn").click(function() {
$(".answerBtn").html(orangeJokes[count + 1]);
});
}
// APPLE SECTION
if (play == 'apple') {
startJokes("appleBg", appleJokes);
nextJoke("green", appleFruitFact, "appleImg", appleJokes);
prevJoke(appleJokes);
resetJokes("appleImg", appleJokes);
$(".answerBtn").click(function() {
$(".answerBtn").html(appleJokes[count + 1]);
});
}
// STRAWBERRY BANANA
if (play == 'strawberryBanana') {
startJokes("strawBanBg", strawberryBananaJokes);
nextJoke("yellow", strawBanFruitFact, "strawBanImg", strawberryBananaJokes);
resetJokes("strawBanImg", strawberryBananaJokes);
$(".answerBtn").click(function() {
$(".answerBtn").html(strawberryBananaJokes[count + 1]);
});
}