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

Alexander Stack
Alexander Stack
2,087 Points

Stuck on random quote generator printQuote function

im going through the random quote generator project and got to the part where you have to write the printQuote function and i am completely drawing a blank. I've tried looking but im having trouble finding a place to review that or use an example piece of code to use as a reference. So far this is what I have.

I am also getting a syntax error in VSC for the ';' on the last line, (that line was given with the project file) and have no idea what to do to fix that.

/*** 
 * `quotes` array 
***/
let quotes = [
  {
    quote: "Life is what happens when you're busy making other plans.",
    source: "John Lennon",
  },
  {
    quote: "I find your lack of faith disturbing.",
    source: "Darth Vader: Star Wars Episode 4: A New Hope",
    year: "1977",
    tag: "Nerdy",
  },
  {
    quote: "Incoming fire has the right of way.",
    source: "Unknown",
    citation: "https://artofteenagestalking.wordpress.com/2008/10/26/cod4-death-quotes/",
    tag: "military",
  },
  {
    quote: "Don’t spend time beating on a wall, hoping to transform it into a door.",
    source: "Coco Chanel",
    citation: "https://www.lifehack.org/articles/communication/30-the-most-inspirational-quotes-all-time.html",
  },
  {
    quote: "Holding onto anger is like drinking poison and expecting the other person to die.",
    source: "Budda",
    citation: "https://www.lifehack.org/articles/communication/30-the-most-inspirational-quotes-all-time.html",
  },

];
/**Random quotes above with each quote in an array, used multiple attributes including the citiation if it was used
 * ` from a website, tags for what catagory they may fall into and the year if known.
***/


/***
 * `getRandomQuote` function
***/

function getRandomQuote() {
  let randomQuote = Math.floor(Math.random() * quotes.length);

  return quotes[randomQuote];

//Random color generator
function getRandomColor () {
  var red = math.floor(math.random() * 256);
  var green = math.floor(math.random() * 256);
  var blue = math.floor(math.random() * 256);
  var colors = 'rgb(' + red +','+ green +', '+ blue +')';
  return colors;
  };

/***
 * `printQuote` function
***/

function printQuote () {


};

/***
 * click event listener for the print quote button
 * DO NOT CHANGE THE CODE BELOW!!
***/

document.getElementById('load-quote').addEventListener("click", printQuote, false);

1 Answer

You're missing the closing curly brace of getRandomQuote()

Alexander Stack
Alexander Stack
2,087 Points

Thank you! that fixed the syntax error but gave me another saying unexpected ";" on line 13 char 5. which is the the q on 'quotes' variable

maybe it doesn't like the last comma in quotes