Random quote generator (Problem)

Random quote generator (Problem)


This is my code and citation and year are optional properties of quotes array but citation and year are not showing when I click show another quote button.

$('.citation').text (""+ citation_text);
$('.year').text(""+ year_text);

There are no such elements on your page. You don’t have anything with the class of citation or year, so you are trying to set the text content of elements that do not exist.


So how can I do this then? Thanks.


In your HTML, you need to add elements in the place where you want the year and citations to be, and give them the appropriate classes. You already have a year and source in your HTML, so if that is where you want them to appear, each can be wrapped in a span with that class, but you’re going to do something else.

You could structure it similar to this:

 <span>the source</span>
 <span>the citation</span>
 <span>the year</span>

putting appropriate classes on each span.


thanks. :slight_smile: