I need help with my project. I can’t figure out what is wrong with my code when I open it in browser it doesen’t display the quotes, please help. Any help is apreciated!
This is my script.js file:
$(document).ready(function(){
var quote;
var author;
function getNewQuote(){
$.ajax({
url: 'http://api.forismatic.com/api/1.0/',
jsonp: 'jsonp',
dataType: 'jsonp',
data: {
method: 'getQuote',
lang: 'en',
format: 'jsonp',
},
success: function(response) {
quote = response.quoteText;
author = response.quoteAuthor;
$("#quote").text(quote);
if(author){
$("#author").text(author);
} else {
$("#author").text("-Unknown Author");
}
}
});
}
getNewQuote();
$('#new-quote').on('click', function(e) {
e.preventDefault();
getNewQuote();
});
$('#tweet-quote').on('click', function(e) {
e.preventDefault();
window.open('https://twitter.com/intent/tweet?text=' + encodeURIComponent(quote));
});
});
And this is my index.html file:
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Allan' rel='stylesheet'>
<link rel="stylesheet" href="style.css">
<title>Random Quote Machine</title>
</head>
<body>
<h1 class="text-center header">Random Quote Machine</h1>
<div class="container text-center">
<p id="quote"></p>
<p id="author"></p>
</div>
<div class="buttons text-center">
<div class="row">
<div class="col-sm-4">
<button class="btn btn-info" id="tweet-quote" target="_blank">Tweet!</button>
</div>
<div class="col-sm-4">
<button class="btn" id="new-quote">New Quote</button>
</div>
</div>
</div>
</body>
</html>
Please help