in the following code when I clic once on task, it prints only once but if I press again on other task it prints twice also if I press again it prints three times,but actually I need it to print just once whenever I clic on any task
const addnewtask = () => {
let newTask = ` <div class="task">
<h2 class="taskname">${lectureName.value}</h2>
<h3 class="tasktime">
<span id="hh">8</span>:
<span id="mm">05</span>:
<span id="ss">05</span>:
<span id="ampm">am</span>
</h3>
<button class="editetask" onclick="editeTask()">Edite</button>
</div>`
tasks.insertAdjacentHTML("afterbegin", newTask)
}
const editeTask = () => {
let alltasks = document.querySelectorAll(".task");
alltasks.forEach((task, index) => {
task.addEventListener("click", () => {
console.log(index)
})
})
newTask.addEventListener("click", addnewtask)