-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.html
More file actions
74 lines (74 loc) · 2.38 KB
/
project.html
File metadata and controls
74 lines (74 loc) · 2.38 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!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>Document</title>
<style>
body{
background-color: #f0eeee;
}
.box{
width: 300px;
height: 300px;
margin: 50px auto;
background-color: #c3c3c3;
box-shadow: 2px 5px 50px rgba(0,0,0,1);
border-radius: 25px;
text-align: left;
padding: 20px;
font-family: Georgia, 'Times New Roman', Times, serif;
}
#name, #eyecolor, #birthyear{
padding: 20px;
color: #ffffff;
font-size: 20px;
}
.get{
border-radius: 25px;
cursor: pointer;
padding: 20px;
color: #ffffff;
background-color: black;
transition: 1.2s;
}
.get:hover{
color: #000;
background-color: rgb(230, 230, 230);
}
</style>
</head>
<body>
<div class="box">
<strong>Name:</strong>
<div id="name"></div>
<strong>Eye-color:</strong>
<div id="eyecolor"></div>
<strong>birth_year:</strong>
<div id="birthyear"></div>
<button class="get">randomize!</button>
</div>
<script>
const name = document.getElementById("name");
const eye_color = document.getElementById("eyecolor");
const birth_year = document.getElementById("birthyear");
const button = document.querySelector(".get")
button.addEventListener('click', (e) => {
e.preventDefault()
name.innerHTML = '<em>loading... </em>';
eyecolor.innerHTML = '<em>loading... </em>';
birthyear.innerHTML = '<em>loading... </em>';
const randomNumber = Math.ceil(Math.random() * 83)
fetch(`https://swapi.dev/api/people/${randomNumber}`)
.then(Response => Response.json())
.then(data =>{
// console.log(data)
name.innerHTML = data['name'];
eyecolor.innerHTML = data['eye_color'];
birthyear.innerHTML = data['birth_year'];
})
})
</script>
</body>
</html>