I am trying to call a function called mytask and pass index variable as a parameter. However, it seems that the compiler doesn’t recognize index.
Here is my code:
fillTask();
function fillTask() {
tasksList.innerHTML = '';
let index = 0;
for (task of tasks) {
let li = document.createElement('li');
li.innerHTML = ' <button onclick="mytask(${index})" class="delete">Delete</button> ';
tasksList.appendChild(li);
//index++;
}
}
//Delete task
function mytask(index) {
alert("Task has been deleted");
}
When I click on the delete button I am getting this error in my console:
Uncaught SyntaxError: missing ) after argument list (at index.html:1:8)