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


Arkadiusz Fabiański
Arkadiusz Fabiański
Full Stack JavaScript Techdegree Student 1,662 Points

Random Quote Generator - request to help with code.

Hello. I got rejection of my code in Quote Generator project. Could anyone check out my code and help me?

// event listener to respond to "Show another quote" button clicks
// when user clicks anywhere on the button, the "printQuote" function is called
document.getElementById('loadQuote').addEventListener("click", printQuote, false);
var randomNumber;
var quoteObject;
var printedText;
var quotes = [
    {quote: "The coldest  winter I ever spent was a summer in San Fransisco.", source: "Mark Twain"},
    {quote: "You can do anyting, but not everything.", source: "Woody Allen"},
    {quote: "Those who dare to fail miserably can achive greatly.", source: "John F. Kennedy"},
    {quote: "The true sign of intelligence is not knowledge but imagination.", source: "Albert Einstein"}

function getRandomQuote(){
    randomNumber = Math.floor(Math.random()*quotes.length); //selects a random quote object from the quotes array
    return quotes[randomNumber];//returns the randomly selected quote object

function printQuote(){
    quoteObject = getRandomQuote(); //calls the getRandomQuote function and stores the returned quote object in a variable
    printedText = "<p class=\"quote\">" + quoteObject.quote + "</p><p class=\"source\"> " + quoteObject.source + "</p>"; //html text
    document.getElementById('quote-box').innerHTML = printedText; //print onto page

What do you mean by "rejection?" Was there some sort of prompt, a spec you had to follow? What was it? Was your non-conformance to the spec the reason for rejection? Or does your code just not work? You'll have better luck attracting quality answers if you specify these things.

1 Answer

Rob Crossland
Rob Crossland
9,158 Points

Try adding the addEventListener after you created the printQuote function