-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (32 loc) · 1008 Bytes
/
app.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
const memeImageText = document.getElementById("memeImage")
const timeLeftText = document.getElementById("timeLeft")
const subredditText = document.getElementById("subredditText")
const linkText = document.getElementById("linkText");
createNewMeme();
function createNewMeme() {
fetch("https://meme-api.com/gimme")
.then((res) => res.json())
.then((data) => {
var url = data["url"];
var subreddit = data["subreddit"];
var link = data["postLink"];
memeImageText.src = url;
subredditText.textContent = subreddit;
linkText.textContent = link;
})
}
function startTimer() {
var timeLeft = 5;
var timerId = setInterval(countdown, 1000);
function countdown() {
if (timeLeft <= -1) {
clearTimeout(timerId);
startTimer();
createNewMeme();
} else {
timeLeftText.textContent = timeLeft;
timeLeft--;
}
}
}
startTimer();