Help with Random Quote Generator

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! :slight_smile:

This is my script.js file:

  var quote;
  var author;
function getNewQuote(){
  url: '',
    jsonp: 'jsonp',
    dataType: 'jsonp',

    data: {
      method: 'getQuote',
      lang: 'en',
      format: 'jsonp',
    success: function(response) {
      quote = response.quoteText;
      author = response.quoteAuthor;
      } else {
        $("#author").text("-Unknown Author");

$('#new-quote').on('click', function(e) {

 $('#tweet-quote').on('click', function(e) {
   e.preventDefault();'' + encodeURIComponent(quote));


And this is my index.html file:

<!DOCTYPE html>
<html lang="en">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
 <script src=""></script>
 <script src=""></script>
 <script src=""></script>
 <link href='' rel='stylesheet'>
 <link rel="stylesheet" href="style.css">
<title>Random Quote Machine</title>

    <h1 class="text-center header">Random Quote Machine</h1>
<div class="container text-center">
<p id="quote"></p>
<p id="author"></p>
<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 class="col-sm-4">
    <button class="btn" id="new-quote">New Quote</button>

Please help :slight_smile:

First thing I notice is that the URL in the ajax call is HTTP. Codepen will block HTTP calls. They must be HTTPS.

Are you building this in regular text editor or codepen? I recommend using codepen as you might get different behavior when you submit your project. You index.html doesn’t link to your JS file.

I’m guessing he’s not using codepen since he’s loading the external files manually.

I do notice in your header that you load the jquery.min.js more than once (two different versions) and you have more than one <html> tag.

I was able to get everything loaded into codepen and it works fine, you can see it here.

The only change I made was switching the ajax call to https, as carbon mentioned. That and getting rid of the head info (codepen likes to handle that.)

The lack of a link to your index.js is a problem, you need something like:

 <script src="index.js"></script>

If you’re going to be sharing these programs and asking lots of questions on the forum, you might consider using something like codepen - it makes it soooooooooooooooo much easier for us to answer your question and try things out to help you find a solution. And it is pretty cool for small little projects like this, very quick to develop and test.

1 Like

Thanks a lot :slight_smile: