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 Random Quote Generator

Bryant Feld
seal-mask
.a{fill-rule:evenodd;}techdegree
Bryant Feld
Full Stack JavaScript Techdegree Student 26,144 Points

unexpected identifier

need new eyes on this, can figure out why I am getting this error

function printQuote() {

var selectedQuote = getRandomQuote(selectedQuote);

var quoteConstruct = "<p class = "quote">" + selectedQuote.quote + "</p>" + "<p class="source ">" + selectedQuote.source + "</p>";

if (selectedQuote.prototype.hasOwnProperty.call(selectedQuote, "citation")) {
    quoteConstruct = quoteConstruct + "<span class="citation ">" + selectedQuote.citation + "</span> <span class="year ">" + selectedQuote.year + "</span> </p>";

    document.write(quoteConstruct);
};

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You have a couple of places in your code where you want the double quotation mark to actually be printed in the string. But because you start the string with a double quotation mark it actually thinks the first quotation you want to be printed is the end of the string.

Here's an example:

"<p class = "quote">"

In this case, Javascript believes the string is starting before the angle bracket and ending just after the equals sign, which isn't what you're intending to do. This also means that it believes quote is a variable name which is why you're receiving the "unexpected identifier". So that part should be rewritten as:

'<p class = "quote">'

This will allow the double quotes to be part of your string literal. There are other instances of this same problem in your code, but I'll leave you to figure out where exactly. Hope this helps! :sparkles: