I am working on developing a to-do list using an array in JavaScript, where the functions are separated from the HTML code. I have managed to set up the HTML structure, but I am facing challenges in completing the necessary functions. Fortunately, the EventListener is functioning properly in my project.
<form id="todoForm">
<input id="todoInput" type="text">
<button type="button" id="button">Add your To Do</button>
</form>
<ol id="toDoList"></ol>
The key components of my project include an array named 'todos', detection of button clicks, and the 'addTodo' function that is triggered upon a click event to add input values to the array. However, I am currently struggling with the next function, 'printTodos', which should display the array items as li elements. This is where I require assistance as the existing content in the 'printTodos' function is not functional.
var todos = [];
document.getElementById('button').addEventListener('click', function
addTodo () {
todos.push('input')
function printTodos () {
var item = document.createElement("li");
var node = createTextNode(input);
// I am stuck
}
});