I am working on a website where each click on the screen reveals a new paragraph gradually. I plan to organize these paragraphs in an array and display them one after the other in sequential order upon user interaction. The challenge lies in combining these two aspects through javascript - while the EventListener function works, incorporating the array for display remains unclear. Any guidance on how to achieve this would be highly appreciated.
document.addEventListener("click", (e) => {
const { clientX, clientY } = e; //get the click position
//create the div
const div = document.createElement("div");
//set its text
div.innerText = "text";
//set its position and position style
div.style.position = "absolute";
div.style.left = clientX + "px";
div.style.top = clientY + "px";
document.body.append(div); //add div to the page
});
Any suggestions on how to integrate the array of paragraphs so that they are displayed one by one with each click?