-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (100 loc) · 2.34 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
background: linear-gradient(to right, lightblue, yellow);
font-family: 'Courier New', Courier, monospace;
}
#main {
background-color: white;
padding: 4vw 5vw;
border-radius: 10px;
box-shadow: 0 10px 20px rgb(0, 0, 0, 0.3);
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#main button {
margin: 2vw;
padding: 0.5vw 0.8vw;
background-color: red;
border: none;
border-radius: 5px;
font-size: 2vw;
color: white;
cursor: pointer;
}
#click:disabled {
background-color: gray;
cursor: not-allowed;
}
#quote {
width: 100%;
font-size: 1.5vw;
background-color: black;
text-align: center;
border-radius: 5px;
color: greenyellow;
padding: 0.5vw 0.7vw;
}
#quotegen {
font-size: 3vw;
}
p {
margin-top: 0.8vw;
background-color: hsla(240, 74%, 48%, 0.696);
color: white;
padding: 0.5vw 0.7vw;
border-radius: 10px;
font-weight: 600;
}
</style>
<body>
<div id="main">
<h3 id="quotegen">Quotes Generator</h3>
<button id="click">Get Quote</button>
<h3 id="quote">Quote</h3>
<p>Author</p>
</div>
<script>
let btn = document.getElementById('click');
let quote = document.getElementById('quote')
let author = document.querySelector('p');
btn.onclick = async function () {
try {
btn.disabled = true
btn.innerHTML = 'Loading ...'
author.innerHTML = 'Loading ...'
quote.innerHTML = 'Updating ...'
const response = await fetch('https://api.quotable.io/random')
const data = await response.json();
author.innerHTML = data.author
btn.disabled = false;
btn.innerHTML = 'Get Quote'
quote.innerHTML = `${data.content}`
}
catch (error) {
btn.disabled = false;
btn.innerText = 'Get Quote'
quote.innerText = 'An error occured... Try Again'
author.innerHTML = 'An error occured... '
}
}
</script>
</body>
</html>