-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
36 lines (29 loc) · 1.14 KB
/
script.js
File metadata and controls
36 lines (29 loc) · 1.14 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
document.addEventListener("DOMContentLoaded", () => {
const startBtn = document.querySelector(".beer-button");
const randomBeer = document.querySelector(".random-beer");
const descriptionDisplay = document.querySelector(".description");
function getData(e) {
e.preventDefault();
fetch("https://api.punkapi.com/v2/beers/random")
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
const name = data[0].name;
console.log(name);
const description = data[0].description;
console.log(description);
const {
volume
} = data[0];
const volumeUnit = volume.unit;
const volumeValue = volume.value;
console.log(volumeUnit);
console.log(volumeValue);
randomBeer.innerHTML = name + " " + volumeValue + volumeUnit;
descriptionDisplay.innerHTML = description;
})
}
startBtn.addEventListener("click", getData);
})