A Pen by seth dehaan on CodePen.
Created
August 28, 2015 12:56
-
-
Save sethxd/ceef84442b2e6ac6e304 to your computer and use it in GitHub Desktop.
chuck norris facts
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 class="center"> | |
<p id="quote"></p> | |
<button class="btn btn-primary" id="getQuote">TELL ME ABOUT CHUCK NORRIS</button> | |
<button class="btn btn-warning" id="tweet">TWEET THIS</button> | |
</div> |
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).ready(function() { | |
var quote = "" | |
$('#getQuote').click(function() { | |
$.getJSON('http://api.icndb.com/jokes/random', function(json) { | |
console.log(json); | |
$('#quote').html('Here is your random Chuck Norris fact:<br><br>' + json.value.joke); | |
quote = json.value.joke; | |
console.log(quote) | |
}) | |
}) | |
$('#tweet').click(function() { | |
if (quote != "") { | |
window.open('https://twitter.com/intent/tweet?text=' + quote, '', 'width=700, height=400') | |
} else { | |
alert("You can't tweet nothin'!") | |
} | |
}) | |
}) |
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="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.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
.center { | |
text-align:center; | |
padding-top:100px; | |
width: 700px; | |
margin:auto; | |
font-size: 1.5em; | |
} | |
#quote { | |
min-height:200px; | |
} |
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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment