Skip to content

Commit 3cc4e16

Browse files
Merge pull request #114 from Raynnnnnnnn/main
Random Quote Genrator
2 parents 38e6074 + 75b7137 commit 3cc4e16

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

Random_Qutote_Genrator/index.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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="styles.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Random Quote Generator</h1>
12+
<p id="quote">Click the button to get a random quote!</p>
13+
<button id="generate">Generate Quote</button>
14+
</div>
15+
<script src="script.js"></script>
16+
</body>
17+
</html>

Random_Qutote_Genrator/script.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Function to fetch a random quote from the Quotable API
2+
async function fetchRandomQuote() {
3+
try {
4+
const response = await fetch('https://api.quotable.io/random');
5+
const data = await response.json();
6+
7+
if (response.ok) {
8+
const randomQuote = `${data.content} - ${data.author}`;
9+
document.getElementById("quote").textContent = randomQuote;
10+
} else {
11+
throw new Error(`Failed to fetch data: ${data.message}`);
12+
}
13+
} catch (error) {
14+
console.error(error);
15+
document.getElementById("quote").textContent = "Failed to fetch a quote. Please try again later.";
16+
}
17+
}
18+
19+
// Attach the event listener to the button
20+
document.getElementById("generate").addEventListener("click", fetchRandomQuote);
21+
22+
// Initial quote fetch
23+
fetchRandomQuote();

Random_Qutote_Genrator/styles.css

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
body {
2+
font-family: Arial, sans-serif;
3+
background-color: #f4f4f4;
4+
text-align: center;
5+
}
6+
7+
.container {
8+
background-color: #fff;
9+
padding: 20px;
10+
border-radius: 5px;
11+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
12+
margin: 20px auto;
13+
max-width: 400px;
14+
}
15+
16+
h1 {
17+
color: #333;
18+
}
19+
20+
button {
21+
background-color: #007BFF;
22+
color: #fff;
23+
border: none;
24+
padding: 10px 20px;
25+
margin-top: 10px;
26+
cursor: pointer;
27+
}
28+
29+
button:hover {
30+
background-color: #0056b3;
31+
}
32+
33+
#quote {
34+
font-style: italic;
35+
}

0 commit comments

Comments
 (0)