Skip to content

Commit f974de2

Browse files
authored
Merge pull request #358 from Sapna2001/quote
Random Quote Generator using JS
2 parents 28726be + 0c881d5 commit f974de2

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Random Quote Generator
2+
This script is used to generate random quotes using the api - https://forismatic.com/.
3+
4+
## How to use
5+
Open index.html in any browser and click on the generate quote button.
6+
7+
## Screenshot
8+
![demo](https://user-images.githubusercontent.com/56690856/99040560-56c22280-25af-11eb-85cf-4db94c459302.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Random Quote Generator</title>
7+
<link rel="stylesheet" href="style.css">
8+
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
9+
</head>
10+
<body>
11+
<div class="container">
12+
<p class="quote"></p>
13+
<p class="author"></p>
14+
</div>
15+
<button id="generate">GENERATE QUOTE</button>
16+
<script src="index.js"></script>
17+
</body>
18+
</html>
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const quote = document.querySelector(".quote");
2+
const author = document.querySelector(".author");
3+
const btn = document.querySelector("button");
4+
url ="https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";
5+
6+
$('#generate').click(function() {
7+
$.getJSON(url)
8+
.done(update)
9+
.fail(handleError);
10+
});
11+
12+
update = (response) => {
13+
quote.innerHTML=`${response.quoteText}`;
14+
author.innerHTML=`- ${response.quoteAuthor}`;
15+
}
16+
17+
handleError = (jqxhr, textStatus, err) => {
18+
console.log("Request Failed: " + textStatus + ", " + err);
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
body {
2+
background-color: #fddb3a;
3+
text-align: center;
4+
}
5+
6+
.container {
7+
background-color: #222831;
8+
color: white;
9+
margin: 10% 20% 3% 20%;
10+
padding: 2%;
11+
font-size: 35px;
12+
border-radius: 50px 0 50px 0;
13+
}
14+
15+
button {
16+
background-color: turquoise;
17+
border-color: black;
18+
color: black;
19+
padding: 15px 32px;
20+
text-align: center;
21+
text-decoration: none;
22+
display: inline-block;
23+
font-size: 24px;
24+
margin: 4px 2px;
25+
cursor: pointer;
26+
border-radius: 5px;
27+
font-weight: 500;
28+
}
29+
30+
.quote {
31+
text-align: center;
32+
}
33+
34+
.author {
35+
text-align: end;
36+
}

0 commit comments

Comments
 (0)