Skip to content

Commit e2017e8

Browse files
committed
Random Cats Generator HTML, CSS and JAVASCRIPT
1 parent cac7c70 commit e2017e8

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

‎77. Random Cat Images/app.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
consturl="https://api.thecatapi.com/v1/images/search";
2+
constsection=document.querySelector(".container");
3+
constbutton=document.querySelector(".btn");
4+
5+
button.addEventListener("click",getRandomCats);
6+
7+
randomCatPhoto=(json)=>{
8+
letphoto=json[0].url;
9+
section.classList.add("cats");
10+
11+
letimage=document.createElement("img");
12+
image.src=photo;
13+
image.classList.add("random_cats");
14+
image.alt=photo;
15+
section.appendChild(image);
16+
};
17+
18+
asyncfunctiongetRandomCats(){
19+
section.innerHTML="";
20+
try{
21+
constresponse=awaitfetch(url);
22+
constjson=awaitresponse.json();
23+
console.log("JSON:",json);
24+
returnrandomCatPhoto(json);
25+
}catch(e){
26+
console.log("This is an error");
27+
console.log(e);
28+
}
29+
}

‎77. Random Cat Images/index.html‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<htmllang="en">
2+
<head>
3+
<metacharset="UTF-8" />
4+
<metahttp-equiv="X-UA-Compatible" content="IE=edge" />
5+
<metaname="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Random Cat Images</title>
7+
<linkrel="stylesheet" href="style.css" />
8+
</head>
9+
<body>
10+
<sectionclass="header-content">
11+
<buttonclass="btn">Get Random Cat</button>
12+
</section>
13+
14+
<divclass="container"></div>
15+
16+
<scriptsrc="app.js"></script>
17+
</body>
18+
</html>

‎77. Random Cat Images/style.css‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
body{
2+
background:rgb(17,17,17);
3+
}
4+
5+
.header-content{
6+
text-align: center;
7+
}
8+
9+
.btn{
10+
background: transparent;
11+
border: none;
12+
background-color:rgb(216,34,74);
13+
color:#fff;
14+
padding:10px20px;
15+
cursor: pointer;
16+
}
17+
18+
/* JavaScript */
19+
.cats{
20+
display: flex;
21+
justify-content: center;
22+
align-items: center;
23+
height:100%;
24+
}
25+
26+
.random_cats{
27+
width:40%;
28+
}
29+
30+
img{
31+
max-width:700px;
32+
height:30rem;
33+
}

0 commit comments

Comments
(0)