Whats wrong with this code can someone Help? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

19th Dec 2018, 12:00 PM
Nidhal Baccouri
Nidhal Baccouri - avatar
10 Answers
+ 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
19th Dec 2018, 1:49 PM
ODLNT
ODLNT - avatar
+ 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.
19th Dec 2018, 4:09 PM
David Carroll
David Carroll - avatar
+ 3
Also... line 70 needs to be changed from: btn.textContent("Delete"); to: btn.textContent = "Delete" ;
19th Dec 2018, 2:25 PM
David Carroll
David Carroll - avatar
+ 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 ();
19th Dec 2018, 1:25 PM
Nidhal Baccouri
Nidhal Baccouri - avatar
+ 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 = ""; }
19th Dec 2018, 1:21 PM
🇵🇰 Danish Khan 🇵🇰
🇵🇰 Danish Khan 🇵🇰 - avatar
+ 1
try adding an event listener document.getElementById("addTodoBtn").addEventListener("click", events.addTodo ());
19th Dec 2018, 1:28 PM
🇵🇰 Danish Khan 🇵🇰
🇵🇰 Danish Khan 🇵🇰 - avatar
+ 1
But thats the Same as using the addBtn.onclick = function ().... Its the Same thing as adding an event listener
19th Dec 2018, 1:35 PM
Nidhal Baccouri
Nidhal Baccouri - avatar
+ 1
Ok thanks i ll try With function
19th Dec 2018, 2:01 PM
Nidhal Baccouri
Nidhal Baccouri - avatar
+ 1
Thanks David but why ?? It is right too to use textContent too
19th Dec 2018, 2:31 PM
Nidhal Baccouri
Nidhal Baccouri - avatar
+ 1
😱 yeah of course how did i Made that mistake 😅😅 thanks
20th Dec 2018, 2:24 AM
Nidhal Baccouri
Nidhal Baccouri - avatar