Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Cool-sami12/cd46c8fd1a6371be80178c4ecf7b301c to your computer and use it in GitHub Desktop.

Select an option

Save Cool-sami12/cd46c8fd1a6371be80178c4ecf7b301c to your computer and use it in GitHub Desktop.
Random quote generator js functions
const quotes = [
{
quote:"Every person who wins in any undertaking must be willing to cut all sources of retreat. Only by doing so can one be sure of maintaining that state of mind known as a burning desire to win - essential to success.",
source:"Napoleon Hill",
citation: "Brainyquote",
year: 2020
},
{
quote:"Fear is the main source of superstition, and one of the main sources of cruelty. To conquer fear is the beginning of wisdom.",
source:"Bertrand Russell",
citation: "Brainyquote",
year: 2020
},
{
quote:"The secret of getting ahead is getting started.",
source:"Mark Twain",
citation: "Brainyquote",
year: 2020
},
{
quote:"The will to win, the desire to succeed, the urge to reach your full potential... these are the keys that will unlock the door to personal excellence.",
source:"Confucius",
citation: "Brainyquote",
year: 2020
},
{
quote:"With the new day comes new strength and new thoughts.",
source:"Eleanor Roosevelt",
citation: "Brainyquote",
year: 2009
},
{
quote:"Knowing is not enough; we must apply. Willing is not enough; we must do.",
source:"Johann Wolfgang von Goethe",
citation: "Brainyquote",
year: 2010
},
{
quote:"Setting goals is the first step in turning the invisible into the visible.",
source:"Tony Robbins",
citation: "Brainyquote",
year: 2020
},
{
quote:"Do the difficult things while they are easy and do the great things while they are small. A journey of a thousand miles must begin with a single step.",
source:"Lao Tzu",
citation: "Brainyquote",
year: 1998
},
{
quote:"Keep your eyes on the stars, and your feet on the ground.",
source:"Theodore Roosevelt",
citation: "Brainyquote",
year: 2020
},
{
quote:"Quality is not an act, it is a habit.",
source:"Aristotle",
citation: "Brainyquote",
year: 1996
},
{
quote:"Failure will never overtake me if my determination to succeed is strong enough.",
source:"Og Mandino",
citation: "Twitter",
year: 2004
},
{
quote:"It’s fine to celebrate success, but it is more important to heed the lessons of failure",
source:"Bill gates",
citation: "Microsoft",
year: 1997
}
]
/***
* `getRandomQuote` function
***/
function getRandomQuote(){
var messagenum = Math.floor(Math.random() * quotes.length);
var message = quotes[messagenum];
return message;
}
/***
* `printQuote` function
***/
function printQuote(){
var newQuote = getRandomQuote()
var messageQuote = '<p class="quote">' + newQuote.quote + '</p>';
var messageSource ='<p class="source">'+ newQuote.source ;
var fullQuote = messageQuote + messageSource;
if (newQuote.citation){
fullQuote += '<span class="citation">' + newQuote.citation + '</span>';
}else if (newQuote.year){
fullQuote += '<span class="year">' + newQuote.year + '</span>';
}else {
fullQuote += '</p>'
}
return document.getElementById('quote-box').innerHTML = fullQuote;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment