Skip to content

To generate a random quote from a text file, you can use a random number generator to select a line from the file.

Notifications You must be signed in to change notification settings

SauRavRwT/Thoughts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 = `
<div class="card rounded-4">
  <div class="card-body">
    <p class="card-text font-monospace">"${quote}"</p>
  </div>
</div>
`;

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();
}

About

To generate a random quote from a text file, you can use a random number generator to select a line from the file.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published