All the HTML used here is generated from JavaScript and the data used is from an array of objects. This mean you can easily add more objects and the app will work without any other changes.
The buttons use onclick
attributes because addEventListener()
won’t work apparently.
How it works
The only HTML on the page is a container for the cards.
The text and image link for each person is kept in an array of objects named testamonials
.
Four functions are used. Pressing the buttons runs either the previousTestamonial()
or nextTestamonial()
. These will call the updatePage()
function IF the currentTestamonial
variable is either less than the total number of the testamonials
array (for the next button) or greater than 0 for the previous button.
These two functions also change the value of the counter