Skip to content

Commit af9b547

Browse files
feat: solved 1st stage of the Hyperskill project "Dog Glossary"
1 parent 5f86fac commit af9b547

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

hyperskill/07_dog_glossary/01/.gitkeep

Whitespace-only changes.

hyperskill/07_dog_glossary/01/app.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
window.onload = function() {
2+
const randomDogButton = document.getElementById('button-random-dog');
3+
const contentDiv = document.getElementById('content');
4+
5+
const dogApiBaseUrl = 'https://dog.ceo/api';
6+
7+
randomDogButton.addEventListener('click', async function() {
8+
const response = await fetch(`${dogApiBaseUrl}/breeds/image/random`);
9+
10+
if (!response.ok) {
11+
contentDiv.innerHTML = 'Error fetching random dog';
12+
return;
13+
}
14+
15+
const data = await response.json();
16+
17+
if (data.status === 'success') {
18+
contentDiv.innerHTML = `<img src="${data.message}" alt="Random dog" />`;
19+
}
20+
});
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Dog Glossary</title>
6+
<link rel="stylesheet" href="style.css">
7+
<script src="app.js" defer></script>
8+
</head>
9+
<body>
10+
<h1>Dog Glossary</h1>
11+
<button id="button-random-dog">Show Random Dog</button>
12+
<div id="content"></div>
13+
</body>
14+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* {
2+
box-sizing: border-box;
3+
}

0 commit comments

Comments
 (0)