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 trialColin Theseira
Full Stack JavaScript Techdegree Student 2,025 PointsAsking feedback review of Random Quote Generator project
https://github.com/seetee10/RQG
Just submitted my project and failed on the getRandomQuote function. I rewrote the function so now the console displays a random quote based on the value generated by the getRandomQuote function. Looks good, however, after the page loads, the console shows the two quotes were called during the page load process. I know why the logic is doing this but I have no idea how to solve it, or if this is truly a problem.
Appreciate any feedback from someone experienced with Javascript.
Thanks.
3 Answers
Juan Lopez
Treehouse Project ReviewerTo resolve the double quotes in console just remove the either line 43 or 119 since console.log(quotes[randomQuotesNumber].quote);
is being called twice. Once in your global randomQuote
variable and the other from printQuote
call.
Also looking over your code the getRandomQuote should return quotes[randomQuoteNumber]
that way when printQuote calls it on line 71 it is then assigned to the variable randomQuote
.
Colin Theseira
Full Stack JavaScript Techdegree Student 2,025 PointsThank you very much for quick response, and reviewing the flaw in my source. After reading your recommendation, I refactored the code and felt the removed all the global variables. That means, the ' return quotes[randomQuoteNumber] ' call may not be necessary.
I tried the project without calling ' return quotes[randomQuoteNumber] ', and that worked as expected, at least from my system :) Do you mind taking a quick peak at the code one more time cause I plan on submitting this project tomorrow.
Colin Theseira
Full Stack JavaScript Techdegree Student 2,025 PointsJust updated the project on GitHub with the auto refresh disabled.
Thanks again for steering me in the right direction. Now I have to work on changing the background color when the page refreshes :)
Colin Theseira
Full Stack JavaScript Techdegree Student 2,025 PointsColin Theseira
Full Stack JavaScript Techdegree Student 2,025 PointsBtw, I commented out the page refresh function to help with the troubleshooting process.