html
html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Dog | Online</title>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="all">
<h2 id="name"></h2>
<div class="display">
<img id="picture">
</div>
<div class="display">
<button id="Generate" class="but">New Dog</button>
<button id="Download" class="but">
<a id="a" class="but" download>Download</a>
</button>
</div>
</div>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
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
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap');
body{
padding-top: 5px;
background-color: dimgrey;
}
#name{
text-align: center;
padding-bottom: 5px;
color: rgb(225, 225, 225);
font-family: 'Roboto', sans-serif;
}
#picture{
border-top-left-radius: 10px;
border-top-right-radius: 10px;
width:40%;
}
.display{
display: flex;
justify-content: center;
}
.but{
text-decoration:none;
color: black;
font-size:18px;
width:20%;
height:60px;
border: 0;
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
let fetchP, url;
window.onload = function(){
GenerateDog();
async function GenerateDog(){
const dogapi = "https://dog.ceo/api/breeds/image/random";
fetchP = await fetch(dogapi);
url = await fetchP.json();
document.getElementById("picture").src = url.message;
document.getElementById("a").href = url.message;
document.getElementById("name").innerHTML = (url.message.split("/")[4]).replace("-", " ")[0].toUpperCase() + (url.message.split("/")[4]).replace("-", " ").slice(1);
}
document.getElementById("Generate").addEventListener('click', function(){
GenerateDog();
})
}
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run