Skip to content

Instantly share code, notes, and snippets.

@sethxd
Created August 28, 2015 12:56
Show Gist options
  • Save sethxd/ceef84442b2e6ac6e304 to your computer and use it in GitHub Desktop.
Save sethxd/ceef84442b2e6ac6e304 to your computer and use it in GitHub Desktop.
chuck norris facts
<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>
$(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'!")
}
})
})
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
.center {
text-align:center;
padding-top:100px;
width: 700px;
margin:auto;
font-size: 1.5em;
}
#quote {
min-height:200px;
}
<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