Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Josias Kabore
seal-mask
.a{fill-rule:evenodd;}techdegree
Josias Kabore
Full Stack JavaScript Techdegree Student 2,652 Points

help to figure what's missing in this code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Random Quotes</title>
    <link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/styles.css">

</head>

<body id="rgbcolor">
  <div class="container">
    <div id="quote-box">
      <p class="quote">You can do anything but not everything</p>
      <p class="source">David Allen<span class="citation">Making It All Work</span><span class="year">2009</span></p>


        </div>
        <button id="loadQuote">Show another quote</button>
    </div>
    <script src="quotes.js" type="text/javascrpit"></script>
</body>

</html>
// event listener to respond to "Show another quote" button clicks
// when user clicks anywhere on the button, the "printQuote" function is called
//object quotes in an array
document.getElementById('loadQuote').addEventListener("click", printQuote, false);


var quotes = [
    {
        quote: "No matter how old you are, there's always something good to look forward to. ",
        source: " Lynn Johnston",
        citation: " For Better or For Worse",
        year: 2004,
        tag: "Hope"
  },
    {
        quote: " You've got to find what you love and that is as true for work as it is for lovers. Your work is going to fill a large part of your life and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what what you do. If you haven't found it yet, keep looking and don't settle. As with all matters of the heart, you'll know when you've found it.",
        source: " Steve Jobs",
        citation: " Stanford Commencement Adress",
        year: 2005,
        tag: "work"
  },
    {
        quote: " If you have only two pennies left in the world, with the first penny, you should buy rice to feed your family. With the second penny, say the wise Japanese, you should buy a lily. The Japanese understand the importance of dreaming...",
        source: "Japanese Proverb",
        citation: "from Lilies Words and Music: Annie Walker",
        year: 1999,
        tag: "Dream"
  },
    {
        quote: " If you don't like someone's story, write your own",
        source: " Chinua Achebe",
        citation: "Things Fall Apart",
        year: 1958,
        tag: "Change"

  },
    {
        quote: " If you can make a woman laugh, you can make her do anything",
        source: "Marilyn Monroe",
        citation: "Unsourced",
        tag: "Love"
},
    {
        quote: " Have you ever been in love? Horrible isn't it? It makes you so vulnerable. It opens your chest and it opens up your heart and it means that someone can get inside you and mess you up",
        source: "  Neil Gaiman",
        citation: " The Sandman, Vol. 9: The Kindly Ones",
        year: 1989,
        tag: "Love"
    },
    {
        quote: " For every minute you are angry you lose sixty seconds of happiness",
        source: "Julian Germain",
        citation: "Book",
        year: 2005,
        tag: "Happiness"
      },
    {
        quote: "Coincidence is God's way of remaining anonymous",
        source: "Albert Einstein",
        citation: "The World As I See It",
        year: 1931,
        tag: "Coincidence"
        },
];

var quote;
var source;
var citation;
var year;
var tag;
var message;
var printQuote();
//function that will display random quotes
Function getRandomQuote(){
    var randomNumber=Math.floor(Math.random()*quotes.lenght);
    for(i=0; i<quotes.length; i++){
        quote=quotes[randomNumber].quote;
        source=quotes[randomNumber].source;
        citation=quotes[randomNumber].citation;
        year=quotes[randomNumber].year;
        tag=quotes[randomNumber].tag;
        message='<p class="quote">' + quote + '</p>';
        message += '<p class="source">' + source +
    '<span class="citation">' + citation + '</span>' +
    '<span class="year">' + year + '</span>' +
    '<span tag="tag">' + tag + '</span>'
'</p>';

        printQuote(message);
        return message;

    };

    };
    var outputDiv = document.getElementById("quote-box");
    outputDiv.innerHTML =quote
};
Steven Parker
Steven Parker
229,608 Points

When posting code, be sure to use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down: Or watch this video on code formatting.

Also, if this is for a course, please also provide a link the course page you are working with.

Josias Kabore
seal-mask
.a{fill-rule:evenodd;}techdegree
Josias Kabore
Full Stack JavaScript Techdegree Student 2,652 Points

I made a few changes but I am still stuck

function getRandomQuote() {
    var randomNumber = Math.floor(Math.random() * quotes.lenght);
    quote=quotes[randomNumber].quote;
        source=quotes[randomNumber].source;
        citation=quotes[randomNumber].citation;
        year=quotes[randomNumber].year;
        tag=quotes[randomNumber].tag;
    message='<p class="quote">' + quote + '</p>';
        message += '<p class="source">' + source +
    '<span class="citation">' + citation + '</span>' +
    '<span class="year">' + year + '</span>'
    '<span tag="tag">' + tag + '</span>'
'</p>';
};
printQuote(){
var quotes=getRandomQuote();
var outputDiv = document.getElementById('quote-box');
    outputDiv.innerHTML = quote;
    if(quote){
    print(message);
};
};
Steven Parker
Steven Parker
229,608 Points

Remember those backticks for formatting need to be on a line by themselves (or just with the name of the language).

1 Answer

Steven Parker
Steven Parker
229,608 Points

You mainly seem to be missing a function named "printQuote".

At line 72 there is "var printQuote();" which in itself is a syntax error. But "printQuote" is the name of the event handler established at the top of the program on line 4, so there should be a function by that name defined somewhere in the code, but it seems to be completely missing.

And on line 74, there is "Function" (with a capital "F") instead of "function".

And down on line 92 there seems to be a stray close brace and semicolon without any corresponding open brace.

Steven Parker
Steven Parker
229,608 Points

After your update I still don't see a definition for "printQuote" — could you be missing the "function" keyword?

Also, I noticed one place where you wrote "lenght" instead of "length".