Hello, and welcome to the forums!
Nice work adding the webpage to have an interface for the project. Taking projects to the next level is a great learning experience.
As for some feedback, I’d suggest separating out the function responsibilities a bit more in future projects. For example, the bulk of your program is inside a function named getRandomColor()
, including the array of 1643 quote objects, and it returns an array with the color, author, and quote. Then there is setRandomColor()
which is setting the color but also populating the quote details in the webpage. This is working right now, but it’s something to be conscious of as you work on larger projects or with a team.
There is a small issue here:
function setRandomColor() {
$("body").css("background-color", getRandomColor()[0]);
$(".qcontainer").html(`"${getRandomColor()[1]}"`);
$(".author").html(`'${getRandomColor()[2]}'`);
}
Since you’re calling getRandomColor() each time you access a different element of the array ([0] for color, [1] for quote, [2] for author), it’s returning a different random array each time. This would mean that the quote wouldn’t match the author most of the time.
What you could do here is call getRandomColor()
once and save the results to a variable, then use that variable with [0], [1], [2] like you’re doing now to get each of the elements. Since getRandomColor()
is only called once, the quote and author are definitely matched up.
I really like that you’ve created an interface for the project and the quote database you found.
Overall, you did a good job. I’m looking forward to seeing your next project.