Skip to content

Commit

Permalink
format code, and make sure it doesn't repeat same quote as before.
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallDoesCoding authored May 11, 2023
1 parent a38da1c commit 140f475
Showing 1 changed file with 87 additions and 76 deletions.
163 changes: 87 additions & 76 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,91 @@
// Array of quotes
var quotes = [
{
text: "The greatest glory in living lies not in never falling, but in rising every time we fall.",
author: "Nelson Mandela"
},
{
text: "The way to get started is to quit talking and begin doing.",
author: "Walt Disney"
},
{
text: "If life were predictable it would cease to be life, and be without flavor.",
author: "Eleanor Roosevelt"
},
{
text: "Life is what happens when you're busy making other plans.",
author: "John Lennon"
},
{
text: "Spread love everywhere you go. Let no one ever come to you without leaving happier.",
author: "Mother Teresa"
},
{
text: "The greatest glory in living lies not in never falling, but in rising every time we fall.",
author: "Nelson Mandela"
},
{
text: "The way to get started is to quit talking and begin doing.",
author: "Walt Disney"
},
{
text: "If life were predictable it would cease to be life, and be without flavor.",
author: "Eleanor Roosevelt"
},
{
text: "Life is what happens when you're busy making other plans.",
author: "John Lennon"
},
{
text: "Spread love everywhere you go. Let no one ever come to you without leaving happier.",
author: "Mother Teresa"
},
// Continue adding more quotes...
{
text: "Success is not final, failure is not fatal: It is the courage to continue that counts.",
author: "Winston Churchill"
},
{
text: "Life is 10% what happens to us and 90% how we react to it.",
author: "Charles R. Swindoll"
},
{
text: "The only way to do great work is to love what you do.",
author: "Steve Jobs"
},
// Add more quotes here...
{
text: "Believe you can and you're halfway there.",
author: "Theodore Roosevelt"
}
];
var quotes = [
{
text: "The greatest glory in living lies not in never falling, but in rising every time we fall.",
author: "Nelson Mandela"
},
{
text: "The way to get started is to quit talking and begin doing.",
author: "Walt Disney"
},
{
text: "If life were predictable it would cease to be life, and be without flavor.",
author: "Eleanor Roosevelt"
},
{
text: "Life is what happens when you're busy making other plans.",
author: "John Lennon"
},
{
text: "Spread love everywhere you go. Let no one ever come to you without leaving happier.",
author: "Mother Teresa"
},
{
text: "The greatest glory in living lies not in never falling, but in rising every time we fall.",
author: "Nelson Mandela"
},
{
text: "The way to get started is to quit talking and begin doing.",
author: "Walt Disney"
},
{
text: "If life were predictable it would cease to be life, and be without flavor.",
author: "Eleanor Roosevelt"
},
{
text: "Life is what happens when you're busy making other plans.",
author: "John Lennon"
},
{
text: "Spread love everywhere you go. Let no one ever come to you without leaving happier.",
author: "Mother Teresa"
},
// Continue adding more quotes...
{
text: "Success is not final, failure is not fatal: It is the courage to continue that counts.",
author: "Winston Churchill"
},
{
text: "Life is 10% what happens to us and 90% how we react to it.",
author: "Charles R. Swindoll"
},
{
text: "The only way to do great work is to love what you do.",
author: "Steve Jobs"
},
// Add more quotes here...
{
text: "Believe you can and you're halfway there.",
author: "Theodore Roosevelt"
}
];

// Function to generate a random quote
function generateRandomQuote() {
var randomIndex = Math.floor(Math.random() * quotes.length);
var quoteElement = document.getElementById("quote");
var authorElement = document.getElementById("author");
quoteElement.textContent = quotes[randomIndex].text;
authorElement.textContent = "- " + quotes[randomIndex].author;
}
// Function to generate a random quote
function generateRandomQuote() {
var storedQuote = localStorage.getItem('previousQuote');
var randomIndex = Math.floor(Math.random() * quotes.length);

// Wait for the document to load
document.addEventListener('DOMContentLoaded', function() {
// Add 'show' class to trigger the animation
var quoteContainer = document.getElementById("quote-container");
quoteContainer.classList.add('show');
// Check if the generated quote is the same as the previous quote
if (storedQuote && storedQuote === quotes[randomIndex].text) {
// Generate a new random quote
randomIndex = (randomIndex + 1) % quotes.length;
}

// Generate a random quote
generateRandomQuote();
});
var quoteElement = document.getElementById("quote");
var authorElement = document.getElementById("author");
quoteElement.textContent = quotes[randomIndex].text;
authorElement.textContent = "- " + quotes[randomIndex].author;

// Store the displayed quote in local storage
localStorage.setItem('previousQuote', quotes[randomIndex].text);
}

// Wait for the document to load
document.addEventListener('DOMContentLoaded', function() {
// Add 'show' class to trigger the animation
var quoteContainer = document.getElementById("quote-container");
quoteContainer.classList.add('show');

// Generate a random quote
generateRandomQuote();
});

0 comments on commit 140f475

Please sign in to comment.