I don’t know why my quote generator doesn’t work. Can somebody help me please to find out where is the problem. Here’s the link https://codepen.io/Rade01/pen/zYZZbRa
Well, first of all, this:
<button onlick ="newQuote()" class="generator">New quote</button>
Unless web dev has gotten a lot more “intimate” than I remember, I think you have a spelling mistake there. I think you want that function to fire off when the button is clicked, not when it is licked. (Dim the lights, cue the Barry White… )
let quotes = quotes[Math.floor(Math.random() * quotes.length)]; document.getElementById('new-quote').innerHTML = quotes;
There are a few problems here. First of all, quotes was already declared above. Secondly, what you are getting there on the first line is declaring a variable that has already been declared. What if we change the variable name to “quote”?
Then you have the problem that that “quote” is not a string but is an object.
When I fix that HTML error, and rename the variable in the function, and dot into that to get the actual quote, the quote properly displays on the screen.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.