-
-
Notifications
You must be signed in to change notification settings - Fork 678
Expand file tree
/
Copy pathscript.js
More file actions
20 lines (16 loc) · 588 Bytes
/
script.js
File metadata and controls
20 lines (16 loc) · 588 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const jokeEl = document.getElementById("joke");
const jokeBtn = document.getElementById("jokeBtn");
const generateJoke = async () => {
const config = {
headers: { Accept: "application/json" },
};
const res = await fetch("https://icanhazdadjoke.com/", config);
const data = await res.json();
jokeEl.innerHTML = data.joke;
// Fetching with .then()
// fetch("https://icanhazdadjoke.com/", config)
// .then((res) => res.json())
// .then((data) => (jokeEl.innerHTML = data.joke));
};
generateJoke();
jokeBtn.addEventListener("click", () => generateJoke());