Skip to content

Instantly share code, notes, and snippets.

@rdesfo
Last active July 16, 2016 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdesfo/860d826bc9f98fe4eaf4d0bb28d8d1ae to your computer and use it in GitHub Desktop.
Save rdesfo/860d826bc9f98fe4eaf4d0bb28d8d1ae to your computer and use it in GitHub Desktop.
quoteChallenge
<div class="container">
<div class="row text-center">
<h2><i class="fa fa-rocket" aria-hidden="true"></i> Futurama Quote Machine</h2>
</div>
<div class="row text-center">
<div class="col-xs-12 well well-lg message">
The message will go here
</div>
</div>
<div class="row text-center">
<div class="col-xs-12">
<button id="getMessage" class="btn btn-default">
Get Quote
</button>
<span class="twitter-share-button">
<button class="btn btn-default">
<i class="fa fa-twitter" aria-hidden="true"></i>
Share
</button>
</span>
</div>
</div>
</div>
var quotes = [{
name: "professor",
quote: "Good news everyone!",
color: "grey"
}, {
name: "zoidberg",
quote: "Hooray!",
color: "blue"
}, {
name: "Bender",
quote: "Lets face it, comedy’s a dead art form. Now tragedy! That’s funny.",
color: "red"
}, {
name: "Amy",
quote: "You’ve gone from crazy like a fox to crazy like Fox News.",
color: "pink"
}, {
name: "Hermes",
quote: "With a warning label this big, you know they gotta be fun!",
color: "green"
}, {
name: "Fry",
quote: "All this prolonged exposure to radiation is making me thirsty.",
color: "orange"
}]
$(document).ready(function() {
function getRandomIntInclusive(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
$("#getMessage").on("click", function() {
var qInt = getRandomIntInclusive(0, quotes.length - 1);
var futQuote = "";
var shareButton = "";
var shareUrl = "";
futQuote += "<blockquote>";
futQuote += "<p>" + quotes[qInt].quote + "</p>";
futQuote += "<footer>" + quotes[qInt].name + "</footer>";
futQuote += "</blockquote>";
shareUrl += '<a class="twitter-share-button" target="_blank" href="https://twitter.com/intent/tweet?text=' + encodeURI(quotes[qInt].quote) + '">';
shareButton += shareUrl;
shareButton += '<button class="btn btn-default">';
shareButton += '<i class="fa fa-twitter" aria-hidden="true"></i> Share';
shareButton += '</button>';
shareButton += '</a>';
$(".message").html(futQuote);
$("body").css("background-color", quotes[qInt].color);
$(".twitter-share-button").html(shareButton);
});
});
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
@rdesfo
Copy link
Author

rdesfo commented Jul 16, 2016

revision 2: adds blockquote and footer elements

@rdesfo
Copy link
Author

rdesfo commented Jul 16, 2016

revision 4: adds twitter button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment