I have this function I'm using to display a character and quote from a json file onto my page, but it will occasionally repeat a quote before running through all the items. How can I prevent it from repeating?
const kaneki = document.querySelector("#kaneki-button");
if (kaneki) {
kaneki.addEventListener("click", function () {
fetch("json/ghoul.json")
.then((response) => response.json())
.then((response) => {
console.log(response);
let animeData = response[Math.floor(Math.random() * response.length)];
document.getElementById("quote").innerHTML = animeData.quote;
document.getElementById("character").innerHTML = animeData.character;
});
});
}