-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (19 loc) · 689 Bytes
/
Copy pathscript.js
File metadata and controls
24 lines (19 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const jokeEl = document.getElementById("joke");
const jokeBtn = document.getElementById("joke-btn");
const generateJoke = () => {
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.chucknorris.io/jokes/random");
xhr.onreadystatechange = function () {
if (this.readyState === 4) {
if (this.status === 200) {
// console.log(JSON.parse(this.responseText).value);
jokeEl.innerHTML = JSON.parse(this.responseText).value;
} else {
jokeEl.innerHTML = "Something Went Wrong (Not Funny)";
}
}
};
xhr.send();
};
jokeBtn.addEventListener("click", generateJoke);
document.addEventListener("DOMContentLoaded", generateJoke);