A small bug, can anybody suggest a fix to it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

A small bug, can anybody suggest a fix to it?

https://code.sololearn.com/Wc9dCb4XbB9Y/?ref=app Tapping on any added task should result in the switching of its text's strike-through status. But the first tap on every added task in the list doesn't do what is supposed (however, any subsequent taps do what is required). Please help.

3rd Oct 2019, 4:45 PM
SSki11
SSki11 - avatar
3 Answers
0
I think your elem.style.textDecoration isn't immediately set to "none" on its creation. This means that, on its first click, since it isn't set to "none" it sets it to "none". Then it works on your second click. Two ways to fix this I can think of: 1) Set task.style.textDecoration = "none"; in your add() method. 2) Change your if statement in your strike() method to if (elem.style.textDecoration != "line-through") { elem.style.textDecoration = "line-through"; } else { elem.style.textDecoration = "none" } Edit: I have no idea why someone downvoted me for this, but just to show but both ways work, I've done them. https://code.sololearn.com/Wlu6tfBaN8rV/?ref=app https://code.sololearn.com/WpmOUztWdoW9/?ref=app
3rd Oct 2019, 5:22 PM
Russ
Russ - avatar
+ 3
Thanks a lot Russ for helping me. This solution works absolutely correctly. Suggestion for the hopeless visitors: please don't downvote an answer if you don't understand it; verify its validity and then respond, because no one has requested your useless response!
5th Oct 2019, 10:18 AM
SSki11
SSki11 - avatar
0
No worries. Glad I could help. Nice code btw!
5th Oct 2019, 11:11 AM
Russ
Russ - avatar