-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (32 loc) · 1.13 KB
/
script.js
File metadata and controls
44 lines (32 loc) · 1.13 KB
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
function set_image(image_src) {
const image = document.getElementById("image")
image.className = "img-fluid"
document.getElementById('loader').className = "spinner-border invisible";
image.onload = function () {
console.log("Image loaded")
document.getElementById("heading").innerText = "Here is a cute random dog";
}
image.src = image_src;
}
function new_dog(){
document.getElementById("loader").className = "spinner-border"
document.getElementById("image").className = "img-fluid invisible"
console.log("Clicked and wants something new");
document.getElementById("heading").innerText = "Loading a new cute puppy";
fetch('https://random.dog/woof.json?filter=mp4,webm')
.then(response => response.json())
.then(data => set_image(data.url))
.catch(err => console.error(err));
}
document.getElementById('button').addEventListener("click", function(){
new_dog();
});
document.body.onload = function () {
new_dog();
}
document.addEventListener('keydown', function(event) {
if (event.keyCode === 78){
console.log(event.keyCode)
new_dog();
}
});