+ 1
Whats wrong with this code can someone Help?
So i wanted to Do a todo app, although IT should ve been easy But something is wrong with the code. I dont know why maybe im missing something. If i write this on my Computer Editor it should work But here in sololearn i get an error. Maybe someone can Help 😆😇 https://code.sololearn.com/WSIX52NW7tNg/?ref=app
10 odpowiedzi
+ 4
An arrow function expression does not have its own (this), you need to use (function)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
+ 4
Nidhal Baccouri Apologies... I was rushing with that answer. I meant to write btn.textContent = "Delete";
I was also going to point out that it works similar to the innerHTML property.
Ultimately, textContent is a property, not a method. Hopefully, that helps clarify my comment.
+ 3
Also... line 70 needs to be changed from:
btn.textContent("Delete");
to:
btn.textContent = "Delete" ;
+ 2
Actually i dont need to add that in HTML because i already implemented it in js : var addTodobtn = document.getElementById('addTodoBtn');
addTodobtn.onclick = () => {
events.addTodo ();
+ 1
you need to add
onclick="functionCall()" to your buttons
e.g.
HTML
<input placeholder="Enter Todo" type="text" id="addTodoInput" />
<button id="updateTodoBtn" onclick="update">Update</button>
javascript
var todo = []; // an array for all you todo
function update(){ // this function is called on click of Update button
// get the value (text) from input and add it to todo array
todo.push(document.getEelementById("addTodoInput").value);
// you might want to clear the input box after adding for new input
document.getEelementById("addTodoInput").value = "";
}
+ 1
try adding an event listener
document.getElementById("addTodoBtn").addEventListener("click", events.addTodo ());
+ 1
But thats the Same as using the addBtn.onclick = function ()....
Its the Same thing as adding an event listener
+ 1
Ok thanks i ll try With function
+ 1
Thanks David but why ?? It is right too to use textContent too
+ 1
😱 yeah of course how did i Made that mistake 😅😅 thanks