-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (35 loc) · 1.25 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function goolash () {
let picNum = Math.floor(Math.random()*(7 - 1) + 1);
console.log(picNum);
if (picNum == 1) {
document.getElementById("chuckPic").src="images/chuck1.png";
} else if (picNum == 2) {
document.getElementById("chuckPic").src="images/chuck2.png";
} else if (picNum == 3) {
document.getElementById("chuckPic").src="images/chuck3.png";
} else if (picNum == 4) {
document.getElementById("chuckPic").src="images/chuck4.png";
} else if (picNum == 5) {
document.getElementById("chuckPic").src="images/chuck5.png";
} else if(picNum == 6) {
document.getElementById("chuckPic").src="images/chuck6.png";
}
}
function refreshPage() {
window.location.reload();
}
let xhr = new XMLHttpRequest();
const url = "https://api.chucknorris.io/jokes/random";
xhr.onreadystatechange = function() {
console.log(xhr.readyState);
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.response);
let joke = JSON.parse(xhr.response); // returns joke in object format
console.log(joke.value);
document.getElementById('content').innerHTML = joke.value; // adds joke value to html (div)
goolash();
}
}
xhr.open("GET", url);
xhr.send();
console.log(xhr);