Skip to content

Instantly share code, notes, and snippets.

@VasVV
Last active July 21, 2020 14:45
Show Gist options
  • Save VasVV/ef3436d6b295cce2987fe3cf3127da80 to your computer and use it in GitHub Desktop.
Save VasVV/ef3436d6b295cce2987fe3cf3127da80 to your computer and use it in GitHub Desktop.
Random Quote Machine - Javascript
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<div id="quote-box">
<div id='text'>
Press a button to see the new quote
</div>
<div id='author'>
made by Vasilii V aka design is not my thing
</div>
<button id='new-quote' onclick='quote()'>New Quote </button>
<a id="tweet-quote" href="https://twitter.com/intent/tweet?text=" target="_blank">Tweet</a>
</div>
const quote = function() {
const quotes = {'Nelson Mandela': 'The greatest glory in living lies not in never falling, but in rising every time we fall', 'Walt Disney' : 'The way to get started is to quit talking and begin doing', 'Eleanor Roosevelt' : 'If life were predictable it would cease to be life, and be without flavor', "Oprah Winfrey" : "If you look at what you have in life, you'll always have more. If you look at what you don't have in life, you'll never have enough", "James Cameron" : "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success", "John Lennon" : "Life is what happens when you're busy making other plans."};
let x = Math.floor(Math.random() * (Object.keys(quotes).length));
let link = document.getElementById('tweet-quote');
document.getElementById("text").innerHTML =
Object.values(quotes)[x];
document.getElementById("author").innerHTML =
Object.keys(quotes)[x];
link.setAttribute('href', "https://twitter.com/intent/tweet?text="+ Object.keys(quotes)[x] + ' told us that ' + Object.values(quotes)[x])
}
body
{
padding: 100px;
background-color:black;
}
#text {
padding: 10px
}
#author {
padding: 10px
}
#quote-box {
background-color:white;
font-family: "Helvetica"
}
button {
margin: 20px
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment