So I'm still learning javascript and for my first to do list project I've gotten to the point where I can add the array to the HTML page but instead of taking the last element and adding it it adds the whole array to each line. How do I change it so only the last element is added instead?
HTML
<!DOCTYPE html>
<html>
<head>
<title>Task Tracker</title>
<link rel="stylesheet" type="text/css" href="todo.css">
<script type="text/javascript" src="todo.js"></script>
</head>
<body>
<div>
<p>Task Manager</p>
<input type="text" name="submitButton" id="userInput">
<button onclick=addTask()>Enter</button>
</div>
<div>
<h3>Task</h3>
<div id='taskList'>
<ul id="myList">
</ul>
</div>
</div>
</body>
</html>
JavaScript
let Task = [];
function addTask(){
var newTask = document.getElementById("userInput").value;
Task.push(newTask);
updateTaskList();
};
function updateTaskList(){
var node = document.createElement('LI');
var textNode;
for (let i = Task.length - 1; i >= 0; i -= 1){
textNode = document.createTextNode(Task[i]);
console.log(Task[i]);
node.appendChild(textNode);
document.getElementById("myList").appendChild(node);
}
}