forked from Rup-Royofficial/Lame_Memes_For_Engineers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
30 lines (25 loc) · 944 Bytes
/
scripts.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
//https://youtu.be/NcUGT_-uoqE
// fetch("https://dog.ceo/api/breeds/image/random")
// .then ( response => response.json())
let btn = document.getElementById("btn")
let meme = document.getElementById("meme")
let text = document.getElementById("txt")
let url = "https://meme-api.com/gimme/"
let subreddits = ["wholesomemes","me_irl","dogmemes","dankmemes","memes"]
let getMemes = () => {
let randomSubreddit = subreddits[Math.floor(Math.random() * subreddits.length)];
// console.log(randomSubreddit);
fetch( "https://meme-api.com/gimme/" + randomSubreddit)
.then((response) => response.json())
.then((data) => {
// console.log(data);
let memeImg = new Image();
memeImg.onload = () => {
meme.src = data.url;
text.innerHTML = data.title;
}
memeImg.src = data.url;
});
};
btn.addEventListener("click", getMemes);
window.addEventListener("load", getMemes);