-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquote.html
136 lines (133 loc) · 3.28 KB
/
quote.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
box-sizing: border-box;
}
body{
background:#bbc6fa;
}
.container{
width: 600px;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
background-color: #fff;
padding: 40px;
border-radius: 7px;
font-weight: 600px;
box-shadow: 0 10px 20px 0px rgba(0,0,0,0.15);
}
.new-quote h1{
text-align: center;
margin-bottom: 40px ;
}
.quotes{
font-size: 21px;
min-height: 190px;
padding-top: 12px;
position: relative;
}
.quotes::backdrop, .quotes::after{
content: "";
}
.quotes span{
display: block;
margin-top: 10px;
position: absolute;
right: 26px;
font-size: 17px;
}
.new-gen{
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.new{
outline: none;
border: none;
border-radius: 10px;
color: #fff;
padding: 8px 14px;
font-size: 17px;
cursor: pointer;
margin-right: 3px;
background-color: rgb(94, 94, 206);
display: flex;
align-items: center;
justify-content: center;
width: 150px;
height: 50px;
}
.tweet img{
width: 30px;
margin-right: 3px;
}
.tweet{
outline: none;
border: none;
border-radius: 10px;
padding: 8px 14px;
font-size: 17px;
color: rgb(94, 94, 206);
cursor: pointer;
margin-right: 3px;
background: transparent;
display: flex;
align-items: center;
justify-content: center;
width: 150px;
height: 50px;
border: 1px black solid;
}
</style>
</head>
<body>
<div class="container">
<h1>Quote of the day</h1>
<div class="quotes">
<blockquote id="online"></blockquote>
<span id="author"></span>
</div>
<div class="new-gen">
<button class="new" onclick="newQuote(apiUrl)">New Quote</button>
<button class="tweet"><img src="https://th.bing.com/th/id/OIP.t1fyvKgDnUoIiC049MG48AHaHa?pid=ImgDet&rs=1" alt="">Tweet</button>
</div>
</div>
<script>
const btn = document.getElementsByClassName("new");
const online = document.getElementById("online");
const author = document.getElementById("author");
const apiUrl = "https://api.quotable.io/random";
async function newQuote(url){
try{
const response = await fetch(url);
const data = await response.json();
console.log(data);
if(response.ok){
online.innerHTML = data.content;
author.innerHTML = data.author;
}
else{
online.innerHTML = "Failed to load a Quote";
author.innerHTML = "??";
}
}catch(error){
console.error("Error:", error);
}
}
btn.addEventListener("click",newQuote(apiUrl));
</script>
</body>
</html>