Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 312ba86

Browse files
Random Users Genrator
1 parent b9e1426 commit 312ba86

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

‎89. Random User/app.js‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const btn = document.getElementById("btn");
2+
3+
btn.addEventListener("click", function () {
4+
getPerson(getData);
5+
});
6+
7+
function getPerson(cb) {
8+
const url = "https://randomuser.me/api/";
9+
const request = new XMLHttpRequest();
10+
11+
request.open("GET", url, true);
12+
request.onload = function () {
13+
if (this.status === 200) {
14+
cb(this.responseText, showData);
15+
}
16+
};
17+
18+
request.send();
19+
}
20+
21+
function getData(response, cb) {
22+
const data = JSON.parse(response);
23+
24+
const {
25+
name: { first },
26+
name: { last },
27+
picture: { large },
28+
location: { street },
29+
phone,
30+
email,
31+
} = data.results[0];
32+
cb(first, last, large, street, phone, email);
33+
}
34+
35+
function showData(first, last, large, street, phone, email) {
36+
document.getElementById("name").textContent = `${first} ${last}`;
37+
document.getElementById("first").textContent = first;
38+
document.getElementById("last").textContent = last;
39+
document.getElementById("street").textContent = street.name;
40+
document.getElementById("phone").textContent = phone;
41+
document.getElementById("email").textContent = email;
42+
document.getElementById("photo").src = large;
43+
}

‎89. Random User/index.html‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<html lang="en">
2+
<head>
3+
<meta charset="UTF-8" />
4+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Random User</title>
7+
<link rel="stylesheet" href="style.css" />
8+
</head>
9+
<body>
10+
<div class="wrapper">
11+
<div class="img-area">
12+
<div class="inner-area">
13+
<img
14+
src="https://images.unsplash.com/photo-1484515991647-c5760fcecfc7?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTh8fG1lbnxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=600&q=60"
15+
id="photo"
16+
/>
17+
</div>
18+
</div>
19+
<div id="name">John Doe</div>
20+
<hr class="horizon" />
21+
<div class="info">
22+
<p>First Name : <span id="first">John</span></p>
23+
<p>Last Name : <span id="last">Doe</span></p>
24+
<p>Location : <span id="street">Earth</span></p>
25+
<p>Phone : <span id="phone">333-333-2222</span></p>
26+
<p>Email : <span id="email">test@gmail.com</span></p>
27+
</div>
28+
29+
<button id="btn">Random Person</button>
30+
</div>
31+
32+
<script src="app.js"></script>
33+
</body>
34+
</html>

‎89. Random User/style.css‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap");
2+
3+
* {
4+
margin: 0;
5+
padding: 0;
6+
box-sizing: border-box;
7+
font-family: "Poppins", sans-serif;
8+
}
9+
10+
body {
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
background-color: #ecf0f3;
15+
min-height: 100vh;
16+
}
17+
18+
.wrapper,
19+
.wrapper .img-area {
20+
background: #ecf0f3;
21+
box-shadow: -3px -3px 7px #fff, 3px 3px 5px #ceced1;
22+
}
23+
24+
.wrapper {
25+
position: relative;
26+
width: 350px;
27+
padding: 30px;
28+
border-radius: 10px;
29+
display: flex;
30+
flex-direction: column;
31+
justify-content: center;
32+
align-items: center;
33+
margin: 15px;
34+
}
35+
36+
.wrapper .img-area {
37+
height: 150px;
38+
width: 150px;
39+
border-radius: 50%;
40+
display: flex;
41+
justify-content: center;
42+
align-items: center;
43+
}
44+
45+
.img-area .inner-area {
46+
height: calc(100% - 25px);
47+
width: calc(100% - 25px);
48+
border-radius: 50%;
49+
}
50+
51+
.inner-area img {
52+
height: 100%;
53+
width: 100%;
54+
border-radius: 50%;
55+
object-fit: cover;
56+
}
57+
58+
.wrapper #name {
59+
font-size: 23px;
60+
font-weight: 500;
61+
color: #31344b;
62+
margin: 10px 0 5px 0;
63+
}
64+
65+
.wrapper #btn {
66+
position: relative;
67+
width: 150px;
68+
border: none;
69+
outline: none;
70+
padding: 5px;
71+
color: #31344b;
72+
font-size: 13px;
73+
font-weight: 450;
74+
border-radius: 5px;
75+
cursor: pointer;
76+
z-index: 4;
77+
margin: 10px 0 15px 0;
78+
background-color: #ecf0f3;
79+
box-shadow: -3px -3px 7px #fff, 3px 3px 5px #ceced1;
80+
}
81+
82+
.wrapper .horizon {
83+
width: 330px;
84+
height: 2px;
85+
border-width: 0;
86+
background: #e4e4e4;
87+
margin: 10px 0 5px 0;
88+
}
89+
90+
.wrapper .info {
91+
color: #44476a;
92+
font-size: 14px;
93+
font-weight: 500;
94+
color: #31344b;
95+
text-align: left;
96+
}
97+
98+
.info p {
99+
margin-bottom: 20px;
100+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /