A Pen by Robert Van Housen on CodePen.
Last active
February 28, 2018 02:09
-
-
Save Javabob61/c0e3ac6bc59f5d05c53aa51697db3a9c to your computer and use it in GitHub Desktop.
Random Quote Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet"> | |
<style> | |
</style> | |
</head> | |
<body id="mybody"> | |
<div id="onlyDiv"> | |
<p id="quoteText" style="font-size:6em;"> | |
"Damn right I've got the blues" </p> | |
<p id="author">- Buddy Guy</p> | |
<button onClick="getAQuote();" id="myButton" class="button" style="font-size: 2em; font-weight: bold;">Get Quote</button> | |
<button onClick="tweetNow()" id="twitterButton" class="fab fa-twitter" class="button" style=" font-size: 5em; font-weight: bold; color: white; background: blue;">Tweet</button> | |
</div> | |
<p style="font-size:2em; color:white; text-align:center;" id="myLine"> - Van Housen</p> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("twitterButton").style.float = left; | |
document.getElementById("twitterButton").color = white; | |
function randomColor() { | |
// This block of code causes a random variation in the background color of the body and the text. | |
var myColors = [ | |
"DarkGreen", | |
"BlueViolet", | |
"Blue", | |
"FireBrick", | |
"Purple", | |
"Indigo", | |
"Red" | |
]; | |
var someNumber = Math.random(); | |
var myRandomColor = Math.floor(someNumber * myColors.length); | |
var newColor = myColors[myRandomColor]; | |
document.getElementById("mybody").style.backgroundColor = newColor; | |
document.getElementById("myButton").style.backgroundColor = newColor; | |
document.getElementById("twitterButton").style.backgroundColor = newColor; | |
document.getElementById("onlyDiv").style.color = newColor; | |
} | |
function getAQuote() { | |
// Randomly selects one of the quotes below. | |
var myNewQuote = [ | |
'"Damn right I\'ve got the blues"', | |
'"I\'d never belong to a club that would have someone like me for a member"', | |
'"You\'re gonna want more cowbell"', | |
'"This one goes to 11"', | |
'"Keep looking up"', | |
'"Chess is ruthless: you\'ve got to be prepared to kill people"', | |
'"When the chess game is over, the pawn and the king go back to the same box"', | |
'"Patriotism is supporting your country all the time, and your government when it deserves it"', | |
'"Go to Heaven for the climate, Hell for the company"', | |
'"Make crime pay. Become a lawyer"', | |
'"True friends stab you in the front"', | |
'"The first principle is that you must not fool yourself and you are the easiest person to fool"' | |
]; | |
var quoteAuthor = [ | |
"- Buddy Guy", | |
"- Woody Allen", | |
"- Bruce Dickinson", | |
"- Nigel Tufnel", | |
"- Neil DeGrasse Tyson", | |
"- Nigel Short", | |
"- Irish saying", | |
"- Mark Twain", | |
"- Mark Twain", | |
"- Will Rodgers", | |
"- Oscar Wilde", | |
"- Richard Feynman" | |
]; | |
var randomNumber = Math.random(); | |
var myRandomNumber = Math.floor(randomNumber * myNewQuote.length); | |
randomColor(); | |
document.getElementById("quoteText").innerHTML = myNewQuote[myRandomNumber]; | |
document.getElementById("author").innerHTML = quoteAuthor[myRandomNumber]; | |
} | |
function tweetNow() { | |
// When the Tweet button is clicked, the quote and its author are sent to twitter. User must enter their hashtag. | |
var newHref = | |
"https://twitter.com/intent/tweet?text=" + | |
document.getElementById("quoteText").innerHTML + | |
" " + | |
document.getElementById("author").innerHTML; | |
window.open(newHref, "_blank"); // To open website using a button without using an anchor use this method for codepen. Also, whenever you redirect in codepen with <a></a> you must include target="_blank"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sharrre/2.0.1/js/platform/twitter.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div { | |
background-color: white; | |
width: 33%; | |
color: blue; | |
padding: 50px; | |
margin: auto; | |
font-size: 8px; | |
font-family: Arial, Helvetica, sans-serif; | |
} | |
body { | |
background-color: blue; | |
} | |
p { | |
text-align: center; | |
font-size: 4em; | |
} | |
.button { | |
background-color: blue; | |
border: none; | |
color: white; | |
padding: 15px 32px; | |
text-align: center; | |
text-decoration: none; | |
display: inline-block; | |
font-size: 16px; | |
cursor: pointer; | |
float: right; | |
font-family: Arial, Helvetica, sans-serif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment