-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
22 lines (17 loc) · 585 Bytes
/
script.js
File metadata and controls
22 lines (17 loc) · 585 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// https://dog.ceo/api/breeds/image/random
// .then - Promises
// asynchronous programming
// stuff you don't have to wait for
console.log('run 1st')
const dogImageDiv = document.getElementById('dogImage')
const dogButton = document.getElementById('dogButton')
// stuff you have to wait for
const getNewDog = () => {
fetch('https://dog.ceo/api/breeds/image/random')
.then(response => response.json())
.then(json => {
dogImageDiv.innerHTML = `<img src='${json.message}' height=300 width=300/>`
})
}
dogButton.onclick = () => getNewDog()
console.log('run 3rd')