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 quotes generation

Hi, My function is named properly and return a random object from the quotes array. However, I got the feedback below. I'm not clear about that. Could someone explain for me? @@ "Function is not named getRandomQuote. Function does not return a random object from the quotes array. Reviewer Comments: Your getRandomQuote function is properly named and it returns a random object from a given array of objects, but in order to meet expectations it needs to return a random object from the quotes array specifically. "

My function here:

// 2. Create the getRandomQuote function and name it getRandomQuote to get a certain quote.
function getRandomQuote(array) {
  let randQuote = array[Math.floor(Math.random() * (quotes.length))];
  return randQuote;
}
Luc de Brouwer
seal-mask
.a{fill-rule:evenodd;}techdegree
Luc de Brouwer
Full Stack JavaScript Techdegree Student 17,939 Points

hi billy, take a look at James his reply, if you're still stuck feel free to join the slack channel where 900 other students and staff / slack champs will be more than likely to help you out with any questions that you have!

1 Answer

Hi Billy,

I can't see how the question is worded, but based on the "Function does not return a random object from the quotes array." feedback it seems a little harsh to me. I would say it meets that requirement.

You could re-write it as something like:

// 2. Create the getRandomQuote function and name it getRandomQuote to get a certain quote.
function getRandomQuote() {
  let randQuote = quotes[Math.floor(Math.random() * (quotes.length))];
  return randQuote;
}

And then just call getRandomQuote() elsewhere in your code.

Hope this helps :)

Thanks, James!!! You're right! It should be a specific array(quotes) to hit the rubric requirement. :)