Skip to content

Commit 3b73c00

Browse files
authored
Refactor joke retrieval and update joke list
1 parent 1d4a855 commit 3b73c00

File tree

1 file changed

+28
-330
lines changed

1 file changed

+28
-330
lines changed
Lines changed: 28 additions & 330 deletions
Original file line numberDiff line numberDiff line change
@@ -1,334 +1,32 @@
11
// Tell me a Joke
22

3-
let myjokes = [
4-
{
5-
"category": "Programming",
6-
"type": "single",
7-
"joke": "// This line doesn't actually do anything, but the code stops working when I delete it.",
8-
"flags": {
9-
"nsfw": false,
10-
"religious": false,
11-
"political": false,
12-
"racist": false,
13-
"sexist": false,
14-
"explicit": false
15-
},
16-
"id": 12,
17-
"safe": true,
18-
"lang": "en"
19-
},
20-
{
21-
"category": "Programming",
22-
"type": "single",
23-
"joke": "\"Honey, go to the store and buy some eggs.\"\n\"OK.\"\n\"Oh and while you're there, get some milk.\"\nHe never returned.",
24-
"flags": {
25-
"nsfw": false,
26-
"religious": false,
27-
"political": false,
28-
"racist": false,
29-
"sexist": false,
30-
"explicit": false
31-
},
32-
"id": 18,
33-
"safe": true,
34-
"lang": "en"
35-
},
36-
{
37-
"category": "Programming",
38-
"type": "single",
39-
"joke": "Saying that Java is nice because it works on every OS is like saying that anal sex is nice because it works on every gender.",
40-
"flags": {
41-
"nsfw": true,
42-
"religious": false,
43-
"political": false,
44-
"racist": false,
45-
"sexist": false,
46-
"explicit": true
47-
},
48-
"id": 30,
49-
"safe": false,
50-
"lang": "en"
51-
},
52-
{
53-
"category": "Programming",
54-
"type": "single",
55-
"joke": "Hey Girl,\nRoses are #ff0000,\nViolets are #0000ff,\nI use hex codes,\nBut I'd use RGB for you.",
56-
"flags": {
57-
"nsfw": false,
58-
"religious": false,
59-
"political": false,
60-
"racist": false,
61-
"sexist": false,
62-
"explicit": false
63-
},
64-
"id": 41,
65-
"safe": true,
66-
"lang": "en"
67-
},
68-
{
69-
"category": "Programming",
70-
"type": "single",
71-
"joke": "\"We messed up the keming again guys.\"",
72-
"flags": {
73-
"nsfw": false,
74-
"religious": false,
75-
"political": false,
76-
"racist": false,
77-
"sexist": false,
78-
"explicit": false
79-
},
80-
"id": 20,
81-
"safe": true,
82-
"lang": "en"
83-
},
84-
{
85-
"category": "Programming",
86-
"type": "single",
87-
"joke": "A SQL statement walks into a bar and sees two tables.\nIt approaches, and asks \"may I join you?\"",
88-
"flags": {
89-
"nsfw": false,
90-
"religious": false,
91-
"political": false,
92-
"racist": false,
93-
"sexist": false,
94-
"explicit": false
95-
},
96-
"id": 5,
97-
"safe": true,
98-
"lang": "en"
99-
},
100-
{
101-
"category": "Programming",
102-
"type": "single",
103-
"joke": "Two SQL tables sit at the bar. A query approaches and asks \"Can I join you?\"",
104-
"flags": {
105-
"nsfw": false,
106-
"religious": false,
107-
"political": false,
108-
"racist": false,
109-
"sexist": false,
110-
"explicit": false
111-
},
112-
"id": 221,
113-
"safe": true,
114-
"lang": "en"
115-
},
116-
{
117-
"category": "Programming",
118-
"type": "single",
119-
"joke": "Documentation is like sex:\nWhen it's good, it's very good.\nWhen it's bad, it's better than nothing...",
120-
"flags": {
121-
"nsfw": true,
122-
"religious": false,
123-
"political": false,
124-
"racist": false,
125-
"sexist": false,
126-
"explicit": false
127-
},
128-
"safe": false,
129-
"id": 305,
130-
"lang": "en"
131-
},
132-
{
133-
"category": "Programming",
134-
"type": "single",
135-
"joke": "\"Can I tell you a TCP joke?\"\n\"Please tell me a TCP joke.\"\n\"OK, I'll tell you a TCP joke.\"",
136-
"flags": {
137-
"nsfw": false,
138-
"religious": false,
139-
"political": false,
140-
"racist": false,
141-
"sexist": false,
142-
"explicit": false
143-
},
144-
"id": 57,
145-
"safe": true,
146-
"lang": "en"
147-
},
148-
{
149-
"category": "Programming",
150-
"type": "single",
151-
"joke": "A byte walks into a bar looking miserable.\nThe bartender asks it: \"What's wrong buddy?\"\n\"Parity error.\" it replies. \n\"Ah that makes sense, I thought you looked a bit off.\"",
152-
"flags": {
153-
"nsfw": false,
154-
"religious": false,
155-
"political": false,
156-
"racist": false,
157-
"sexist": false,
158-
"explicit": false
159-
},
160-
"id": 24,
161-
"safe": true,
162-
"lang": "en"
163-
},
164-
{
165-
"category": "Programming",
166-
"type": "single",
167-
"joke": "UDP is better in the COVID era since it avoids unnecessary handshakes.",
168-
"flags": {
169-
"nsfw": false,
170-
"religious": false,
171-
"political": false,
172-
"racist": false,
173-
"sexist": false,
174-
"explicit": false
175-
},
176-
"id": 259,
177-
"safe": true,
178-
"lang": "en"
179-
},
180-
{
181-
"category": "Dark",
182-
"type": "single",
183-
"joke": "I'll never forget my Granddad's last words to me just before he died. \"Are you still holding the ladder?\"",
184-
"flags": {
185-
"nsfw": false,
186-
"religious": false,
187-
"political": false,
188-
"racist": false,
189-
"sexist": false,
190-
"explicit": false
191-
},
192-
"id": 208,
193-
"safe": false,
194-
"lang": "en"
195-
},
196-
{
197-
"category": "Misc",
198-
"type": "single",
199-
"joke": "My wife is really mad at the fact that I have no sense of direction.\nSo I packed up my stuff and right.",
200-
"flags": {
201-
"nsfw": false,
202-
"religious": false,
203-
"political": false,
204-
"racist": false,
205-
"sexist": false,
206-
"explicit": false
207-
},
208-
"id": 201,
209-
"safe": true,
210-
"lang": "en"
211-
},
212-
{
213-
"category": "Programming",
214-
"type": "single",
215-
"joke": "Debugging is like being the detective in a crime movie where you're also the murderer at the same time.",
216-
"flags": {
217-
"nsfw": false,
218-
"religious": false,
219-
"political": false,
220-
"racist": false,
221-
"sexist": false,
222-
"explicit": false
223-
},
224-
"id": 42,
225-
"safe": true,
226-
"lang": "en"
227-
},
228-
{
229-
"category": "Programming",
230-
"type": "single",
231-
"joke": "The glass is neither half-full nor half-empty, the glass is twice as big as it needs to be.",
232-
"flags": {
233-
"nsfw": false,
234-
"religious": false,
235-
"political": false,
236-
"racist": false,
237-
"sexist": false,
238-
"explicit": false
239-
},
240-
"id": 23,
241-
"safe": true,
242-
"lang": "en"
243-
},
244-
{
245-
"category": "Programming",
246-
"type": "single",
247-
"joke": "Eight bytes walk into a bar.\nThe bartender asks, \"Can I get you anything?\"\n\"Yeah,\" reply the bytes.\n\"Make us a double.\"",
248-
"flags": {
249-
"nsfw": false,
250-
"religious": false,
251-
"political": false,
252-
"racist": false,
253-
"sexist": false,
254-
"explicit": false
255-
},
256-
"id": 34,
257-
"safe": true,
258-
"lang": "en"
259-
},
260-
{
261-
"category": "Pun",
262-
"type": "single",
263-
"joke": "How do you make holy water? You boil the hell out of it.",
264-
"flags": {
265-
"nsfw": false,
266-
"religious": true,
267-
"political": false,
268-
"racist": false,
269-
"sexist": false,
270-
"explicit": false
271-
},
272-
"id": 202,
273-
"safe": false,
274-
"lang": "en"
275-
},
276-
{
277-
"category": "Programming",
278-
"type": "single",
279-
"joke": "I've got a really good UDP joke to tell you but I don’t know if you'll get it.",
280-
"flags": {
281-
"nsfw": false,
282-
"religious": false,
283-
"political": false,
284-
"racist": false,
285-
"sexist": false,
286-
"explicit": false
287-
},
288-
"id": 0,
289-
"safe": true,
290-
"lang": "en"
291-
},
292-
{
293-
"category": "Dark",
294-
"type": "single",
295-
"joke": "I hate double standards. Burn a body at a crematorium, you're \"being a respectful friend.\" Do it at home and you're \"destroying evidence.\"",
296-
"flags": {
297-
"nsfw": false,
298-
"religious": false,
299-
"political": false,
300-
"racist": false,
301-
"sexist": false,
302-
"explicit": true
303-
},
304-
"safe": false,
305-
"id": 274,
306-
"lang": "en"
307-
},
308-
{
309-
"category": "Misc",
310-
"type": "single",
311-
"joke": "What does the MacBook have in common with Donald Trump?\n\nI would tell you....\nBut I don't compare apples to oranges.",
312-
"flags": {
313-
"nsfw": false,
314-
"religious": false,
315-
"political": true,
316-
"racist": false,
317-
"sexist": false,
318-
"explicit": false
319-
},
320-
"id": 233,
321-
"safe": false,
322-
"lang": "en"
323-
}
324-
]
3+
const myJokes = [
4+
"This line doesn't actually do anything, but the code stops working when I delete it.",
5+
"Honey, go to the store and buy some eggs.\nOK.\nOh and while you're there, get some milk.\nHe never returned.",
6+
"Saying that Java is nice because it works on every OS is like saying that something is nice because it works everywhere.",
7+
"Hey Girl,\nRoses are #ff0000,\nViolets are #0000ff,\nI use hex codes,\nBut I'd use RGB for you.",
8+
"We messed up the kerning again guys.",
9+
"A SQL statement walks into a bar and sees two tables.\nIt asks: may I join you?",
10+
"Two SQL tables sit at the bar.\nA query asks: Can I join you?",
11+
"Documentation is like life.\nWhen it's good, it's very good.\nWhen it's bad, it's still better than nothing.",
12+
"Can I tell you a TCP joke?\nPlease tell me a TCP joke.\nOK, I'll tell you a TCP joke.",
13+
"A byte walks into a bar.\nBartender: What's wrong?\nByte: Parity error.\nBartender: You do look a bit off.",
14+
"UDP is better sometimes because it avoids unnecessary handshakes.",
15+
"I'll never forget my granddad's last words to me:\nAre you still holding the ladder?",
16+
"My wife got angry because I have no sense of direction.\nSo I packed my bags and right.",
17+
"Debugging is like being the detective in a crime movie where you're also the criminal.",
18+
"The glass is neither half full nor half empty.\nThe glass is twice as big as it needs to be.",
19+
"Eight bytes walk into a bar.\nBartender: What will you have?\nBytes: Make us a double.",
20+
"How do you make holy water?\nYou boil the hell out of it.",
21+
"I've got a really good UDP joke to tell you, but I don’t know if you'll get it.",
22+
"I hate double standards.\nDo something officially and it's respectful.\nDo it privately and it's suspicious.",
23+
"What does a MacBook have in common with a famous politician?\nI won’t compare apples to oranges."
24+
];
32525

326-
let jokeBtn = document.getElementById("jokeBtn");
327-
let joke = document.getElementById("joke")
26+
const jokeBtn = document.getElementById("jokeBtn");
27+
const joke = document.getElementById("joke");
32828

329-
jokeBtn.addEventListener("click", function () {
330-
let index = Math.floor(Math.random() * myjokes.length)
331-
332-
console.log(index)
333-
joke.innerText = myjokes[index].joke
334-
})
29+
jokeBtn.addEventListener("click", () => {
30+
const randomIndex = Math.floor(Math.random() * myJokes.length);
31+
joke.innerText = myJokes[randomIndex];
32+
});

0 commit comments

Comments
 (0)