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

I need help with random quote generator project

the code

var quotes = [
    {
        quote: " I enjoy fun. I both have fun and can be fun. But when it's about serious things  I am serious",
        source: "Me myself and I",
        citation: "www.brainyquote.com",
        tags: ["Inspirational" ,  "Strength"]
    },........
]

document.getElementById('loadQuote').addEventListener("click", printQuote, false);

function printQuote(){
     document.getElementById("quote-box").innerHTML =   '<p class="quote">' +  quotes[getRandomNr()].quote + '</p>'
                +  '<p class="source">' + quotes[getRandomNr()].source + '<span class="citation">'+ quotes[getRandomNr()].citation + '</span></p>'
                + '<p><span class="tag">' + quotes[getRandomNr()].tags[0]   +' </span> <span class="tag">' + quotes[getRandomNr()].tags[1] + '</span></p>' ;  

}

function getRandomNr () {
     var randomNr = Math.floor(Math.random() * quotes.length);
     return randomNr;
} 

getRandomNr();

document.getElementById('loadQuote2').addEventListener("click", printRandomQuote, false);

var viewedQuotes = [];                                      // array to hold viewed quotes

function getRandomQuote() {
  if (quotes.length == 0)                                   // if empty, reload the main list
    quotes = viewedQuotes.splice(0, viewedQuotes.length);   // (and empty viewed list)
  var randNum = Math.floor(Math.random() * quotes.length);  // pick a quote at random
  var quote = quotes.splice(randNum, 1)[0];                 // take it out of the main list
  viewedQuotes.push(quote);                                 // now add it to the "viewed" list
  return quote;                                             // return the chosen quote
}

//getRandomQuote(quotes); 

 function printRandomQuote(){
    //console.log('heloo');
     document.getElementById("quote-box").innerHTML =   '<p class="quote">' +  getRandomQuote().quote + '</p>'
                +  '<p class="source">' + getRandomQuote().source + '<span class="citation">'+ getRandomQuote().citation + '</span></p>'
                + '<p>'+ taguri  + '</p>';  

}

this iss not working

for(i=0; i<= getRandomQuote().tags.length; i++){
     var taguri = '<p><span class="tag">' + getRandomQuote().tags[i] +'</span>'; 
}

what is the best solution in order to output the tags ? please help

[MOD: edited code block - srh]