Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Quote Generator App #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Quote Generator App/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quote Generator</title>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="container">
<h1><span>Generate a</span> <strong>random quote</strong></h1>
<div class="quote-container">
<button id="quote-btn">Generate quote</button>
<p id="quote"></p>
<p id="author"></p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions Quote Generator App/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//Note: Replay the apiKey with you API KEY from api-ninjas
var apiKey = 'YOUR_API_KEY';
var category = 'happiness';

// Function to fetch a random quote from the API
function fetchQuote() {
$.ajax({
method: 'GET',
url: 'https://api.api-ninjas.com/v1/quotes?category=' + category,
headers: { 'X-Api-Key': apiKey },
contentType: 'application/json',
success: function(result) {
if (result.length > 0) {
displayQuote(result[0].quote, result[0].author);
} else {
displayError('No quotes available.');
}
},
error: function ajaxError(jqXHR) {
console.error('Error: ', jqXHR.responseText);
displayError('An error occurred while fetching the quote.');
}
});
}

// Function to display the fetched quote
function displayQuote(quote, author) {
$('#quote').text('"' + quote + '"');
$('#author').text('- ' + author);
}

// Function to display an error message
function displayError(message) {
$('#quote').text(message);
$('#author').text('');
}

// Event listener for button click to fetch a new quote
$('#quote-btn').on('click', fetchQuote);

// Fetch an initial quote when the page loads
$(document).ready(fetchQuote);
64 changes: 64 additions & 0 deletions Quote Generator App/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: 'Arial', sans-serif;
background-color: #090b0c;
color: #ffffff;
}

h1 {
color: #ffffff;
font-size: 2.5rem;
margin: 20px 0 10px 20px;
}

h1 span {
color: #B0BEC5;
}

h1 strong {
color: #3063ed;
}

.quote-container {
margin-left: 20px;
}

button {
padding: 12px 30px;
font-size: 1.2rem;
color: #ffffff;
background-color: #0036c9;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-bottom: 20px;
}

button:hover {
background-color: #16358a;
}

#quote {
padding: 15px;
border-radius: 8px;
color: #B0BEC5;
width: 80%;
font-size: 1.2rem;
text-align: center;
margin-bottom: 10px;
}

#author {
padding: 8px;
border-radius: 8px;
color: #B0BEC5;
font-size: 1rem;
width: 80%;
text-align: center;
}