-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
22 lines (21 loc) · 721 Bytes
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
window.onload = function () {
let button = document.getElementById("btn");
button.addEventListener("click", get_joke_of_the_day)
get_joke_of_the_day()
}
// checking something
function get_joke_of_the_day() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// Access the result here
let para = document.querySelector('p')
let jokeTitle = document.querySelector('h2')
let response = JSON.parse(this.responseText)
para.innerHTML = response.punchline
jokeTitle.innerHTML = response.setup
}
};
xhttp.open("GET", "https://official-joke-api.appspot.com/random_joke", true);
xhttp.send();
}