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

Project 1,A Random Quote Generator i am a bit stuck, when i try to press the button it wont show another qoute, help!

My code has a few errors, this is my code below for your reference. its not running well

JS CODE: /****************************************** Treehouse FSJS Techdegree: project 1 - A Random Quote Generator ******************************************/

// For assistance: // Check the "Project Resources" section of the project instructions // Reach out in your Slack community - https://treehouse-fsjs-102.slack.com/app_redirect?channel=chit-chat

var quotes = [ {quote: 'Donโ€™t raise your voice, improve your argument.', source: 'Harvey Specter', citation: 'Harvey Specter-Suits (American TV series)', year: '2011'},

{quote: 'Never destroy anyone in public when you can accomplish the same result in private.', source: 'Harvey Specter', citation: 'Harvey Specter-Suits (American TV series)', year: '2012'},

{ quote: 'Let them hate. Just make sure they spell your name right.', source: 'Harvey Specter', citation: 'Harvey Specter-Suits (American TV series)', year: '2013'},

{ quote: 'People respond to how weโ€™re dressed, so like it or not this is what you have to do.', source: 'Harvey Specter', citation: 'Harvey Specter-Suits (American TV series)', year: '2014'},

{ quote: "Sometimes good guys gotta do bad things to make the bad guys pay.", source: 'Harvey Specter', citation: 'Harvey Specter-Suits (American TV series)', year: '2011'} ]; window.onload = function(event){ printQuote(); window.setInterval(printQuote, 20000); };

//https://stackoverflow.com/questions/1531093/how-do-i-get-the-current-date-in-javascript

function getRandomNumber(topNumber) { return Math.floor(Math.random() * topNumber); }

var random = 0; var previousNumber = 0;

function print(message) { var outputDiv = document.getElementById('quote-box'); outputDiv.innerHTML = message; };

var getRandomQuote = function (array) { var random = Math.floor(Math.random() * (quotes.length)); var randomQuote = quotes[random];

return randomQuote; }

//https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array function randomize() { var rgbcolor; red = Math.floor(Math.random() * 250 + 0); green = Math.floor(Math.random() * 250 + 0); blue = Math.floor(Math.random() * 250 + 0);

rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; document.body.style.background = rgbColor;

red = ("0" + red.toString(16)).substr(-2).toUpperCase(); green = ("0" + green.toString(16)).substr(-2).toUpperCase(); blue = ("0" + blue.toString(16)).substr(-2).toUpperCase(); }

function printQuote() { var message = "";
var result = getRandomQuote(quotes); message = "<p class='quote'>" + result.quote + "</p>"; message += "<p class='source'>" + result.source; message += "<span class='citation'>" + result.citation + "</span>"; message += "<span class='year'>" + result.year + "</span>" message += "</p>";

document.getElementById('quote-box').innerHTML = message; }

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

Any hints and suggestions are welcome and very much appreciated.

1 Answer

Robert Manolis
STAFF
Robert Manolis
Treehouse Guest Teacher

Hey Karl Russell Sumando Menil, the best way to get help with this is to reach out in our TD Slack and share a link to your repo so we can test the code locally. Trying to read, understand and debug long code snippets is prohibitively time-consuming, inefficient and ineffective. :thumbsup: