I got Uncaught TypeError: Cannot read property 'addEventListener' of null. I have tried to click the nextButton and prevButton but they are unresponsive. The event listener for the window works fine.
const img = document.getElementById("person-img");
const author = document.getElementById("author");
const job = document.getElementById("job");
const info = document.getElementById("info");
const prevBtn = document.querySelector("prev-btn");
const nextBtn = document.querySelector("next-btn");
const randomBtn = document.querySelector("random-btn");
let currentItem = 0;
window.addEventListener("DOMContentLoaded", function() {
showPerson(currentItem);
});
function showPerson(person) {
const item = reviews[person];
img.src = item.img;
author.textContent = item.name;
job.textContent = item.job;
info.textContent = item.text;
}
nextBtn.addEventListener("click", function() {
currentItem++;
if (currentItem > reviews.length - 1) {
currentItem = 0;
}
showPerson(currentItem);
});
prevBtn.addEventListener("click", function() {
currentItem--;
if(currentItem < 0) {
currentItem = reviews.length - 1;
}
showPerson(currentItem);
});