Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Arkadiusz Fabiański
seal-mask
.a{fill-rule:evenodd;}techdegree
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