Created
May 17, 2018 22:29
-
-
Save waldothedeveloper/3a3c37dbc6aa23791e8b65a6039e27e0 to your computer and use it in GitHub Desktop.
FreeCodeCamp Random Quotes App
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(() => { | |
console.log('ready!'); | |
$("i#tweet-icon").on("click", () => { | |
let quote = $.trim($("#quote").text()); | |
window.open(`https://twitter.com/intent/tweet?text=${quote}`); | |
}); | |
let endpoint = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?'; | |
let getRandomQuote = () => { | |
$.getJSON(`${endpoint}`, (data) => { | |
$("#quote").html(`<i class="fas fa-quote-left"></i> ${data.quoteText} <i class="fas fa-quote-right"></i>`); | |
//Checking if the quote does not have an author | |
if (data.quoteAuthor !== "") { | |
$("#quote-author").html(`${data.quoteAuthor} at <a href="${data.quoteLink}" target="_blank" class="card-link">forismatic</a>`); | |
} else { | |
$("#quote-author").html(`Unknown at: <a href="${data.quoteLink}" target="_blank" class="card-link">forismatic</a>`); | |
} | |
}); | |
//Create a tweet function | |
function tweetQuote() { | |
window.open(`https://twitter.com/intent/tweet?text=${data.quoteText}`); | |
} | |
$("#tweet-icon").on("click", tweetQuote); | |
};//end of getRandomQuote | |
$("#quote-button").on("click", getRandomQuote); | |
});// end of document.ready |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" | |
crossorigin="anonymous"> | |
<!-- Font Awesome icons --> | |
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" | |
crossorigin="anonymous"> | |
<title>Random Quotes App</title> | |
<style> | |
body { | |
background-color: #333 !important; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container mt-5"> | |
<div class="row"> | |
<div class="card mt-5 mx-auto" style="width: 32rem; height: 23rem;"> | |
<div class="card-header justify-content-between" style="display: flex;"> | |
<small class="text-left">Random Quotes</small> | |
<i id="tweet-icon" class="text-right fab fa-twitter fa-lg"></i> | |
</div> | |
<div class="card-body"> | |
<blockquote class="blockquote mb-0"> | |
<p id="quote" style="height: 8rem;"> | |
<i class="fas fa-quote-left"></i> Never apologize for showing feelings. When you do so, you apologize for the truth. | |
<i class="fas fa-quote-right"></i> | |
</p> | |
<footer id="quote-author" class="blockquote-footer mt-3"> | |
Benjamin Disraeli | |
</footer> | |
<div class="row"></div> | |
<a id="quote-button" href="#" class="mt-3 mb-3 btn btn-dark">Next</a> | |
<div class="card-footer bg-transparent border-dark"> | |
<small>Thanks to | |
<a href="http://forismatic.com/en/">forismatic.com</a> for their awesome quotes API | |
</small> | |
</div> | |
</blockquote> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Optional JavaScript --> | |
<!-- jQuery first, then Popper.js, then Bootstrap JS --> | |
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" | |
crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" | |
crossorigin="anonymous"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" | |
crossorigin="anonymous"></script> | |
<!-- Local javascript --> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment