https://github.com/sauravrwt/thoughts
To generate a random quote from a text file, you can use a random number generator to select a line from the file.
https://github.com/sauravrwt/thoughts
bootstrap css javascript thoughts txt-files
Last synced: 6 months ago
JSON representation
To generate a random quote from a text file, you can use a random number generator to select a line from the file.
- Host: GitHub
- URL: https://github.com/sauravrwt/thoughts
- Owner: SauRavRwT
- Created: 2023-11-22T05:13:14.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-20T14:09:06.000Z (over 1 year ago)
- Last Synced: 2024-05-20T15:40:14.542Z (over 1 year ago)
- Topics: bootstrap, css, javascript, thoughts, txt-files
- Language: JavaScript
- Homepage: https://sauravrwt.github.io/Thoughts/
- Size: 242 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Random Quotes
To generate a **random quote** from a text file, you can use a random number generator to select a line from the file. By reading the text file line by line and storing each line in an array or list, you can then generate a random index within the range of the array's length. This index will correspond to a randomly chosen quote from the file. You can then display this quote to the user.
_Pagination -_
let currentPage = 1;
let pageSize = 12;_Change File Path -_
const response = await fetch("Your_file.txt");
_Function to display quotes for the current page -_
async function displayQuotesForPage() {
const { quotesForPage, totalQuotes } = await fetchQuotesForPage(currentPage);
if (quotesForPage.length === 0 && currentPage > 1) {
// If no quotes are available and not on the first page, go back to page 1
currentPage = 1;
await displayQuotesForPage();
return;
}_Function to create a quote element -_
quoteElement.innerHTML = `
"${quote}"
`;
_Function to display modal with the clicked quote -_function displayModal(quote) {
const modalBody = document.getElementById("quoteModalBody");
modalBody.textContent = quote;
const modal = new bootstrap.Modal(document.getElementById("quoteModal"));
modal.show();
}_Function to load the next page of quotes -_
async function loadNextPage() {
currentPage++;
const { quotesForPage } = await fetchQuotesForPage(currentPage);
if (quotesForPage.length === 0) {
// Reset to page 1 if no quotes are available
currentPage = 1;
}
await displayQuotesForPage();
}---
