I'm encountering an issue with the code below. The code is for a simple To Do app using Javascript. I followed a tutorial step by step, but my app isn't functioning as expected. When I press the enter key, the input value should be added to the list, but it's not happening. I've checked the code multiple times and can't seem to find any mistakes.
Even when I manually call the function addToDo("read");
, it works fine. However, pressing the enter button doesn't trigger the function. Any suggestions or advice would be greatly appreciated.
document.addEventListener("keyup", function(event) {
if (event.key === 13) {
const toDo = input.value;
if (toDo) {
addToDo(toDo);
} //end if toDo
} // end if event.key
});