Hello I’m trying to build a todo list app using javascript
for some reason inputValue = "";
reassignment is not working
it is supposed to clear the input field as soon as I press enter or add
Any help is appreciated
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="body">
<div class="todo">
<button class="todo--btn">Add</button>
<input type="text" class="todo--input">
<div class="todo--text-container"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
const addBtn = document.querySelector(".todo--btn");
const todoTextContainer = document.querySelector(".todo--text-container");
let todoInput = document.querySelector(".todo--input");
// console.log(addBtn, todoInput, todoTextContainer);
addBtn.addEventListener("click", createElement);
todoInput.addEventListener("keydown", function (e) {
let keycode = 13;
if (e.keyCode == keycode) {
return createElement();
}
});
function createElement() {
let inputValue = todoInput.value;
let newElement = document.createElement("p");
newElement.innerText = inputValue;
todoTextContainer.appendChild(newElement);
inputvalue = " ";
}