+ 1

[SOLVED]Why my code is not working?

https://sololearn.com/compiler-playground/WpcagVoCUwVO/?ref=app When i click on play button. I expect that icon get removed. But instead. It's showing error. The error arises because of line 53-57 of javascript. But I have no idea why!

21st Jul 2025, 3:13 AM
Manav Roy
Manav Roy - avatar
11 Respuestas
+ 2
Manav Roy do this instead: Array.from(document.getElementsByClassName("songItemList")).forEach((e)=>{ e.addEventListener("click",function(){ // change to this: e.classList.remove("far", "fa-play-circle"); }); });
21st Jul 2025, 3:48 AM
Bob_Li
Bob_Li - avatar
+ 1
Event listener Incomplete... Array.from(document.getElementsByClassName("songItemList")).forEach((e)=>{ e.addEventListener("click",function(){ e.target.classList.remove("far fa-play-circle"); // The logic to play the specific song is missing
21st Jul 2025, 3:22 AM
Zero
Zero - avatar
+ 1
Music switching does not happen in the code There are some variables that are not used yet in your project
21st Jul 2025, 3:23 AM
Zero
Zero - avatar
+ 1
Zero I think it's the same code I've written 😅
21st Jul 2025, 3:24 AM
Manav Roy
Manav Roy - avatar
+ 1
Yeah yeah, but it is incomplete and that is the error. Do you want me to send the correct code? I don't think that's right...
21st Jul 2025, 3:26 AM
Zero
Zero - avatar
+ 1
Your code: Array.from(document.getElementsByClassName("songItemList")).forEach((e)=>{ e.addEventListener("click",function(){ e.target.classList.remove("far fa-play-circle"); The fix: Array.from(document.getElementsByClassName("songItemList")).forEach((e)=>{ e.addEventListener("click", function() { // Toggles between play and pause for the clicked icon this.classList.toggle("fa-play-circle"); this.classList.toggle("fa-pause-circle");
21st Jul 2025, 3:36 AM
Zero
Zero - avatar
0
Zero Music switching doesn't happen in my code cuz it's only 40% completed and I'm yet to add all the features... I just want it remove the play icon when i click on it. But it's throwing error and idk why. What do u mean by "Event listener incomplete"?
21st Jul 2025, 3:28 AM
Manav Roy
Manav Roy - avatar
0
Ah now what you want makes sense. The code recognizes that the music player is incorrect so far.
21st Jul 2025, 3:33 AM
Zero
Zero - avatar
0
About the Incomplete Event Listener, the music playback doesn't work... As an example, we only have the first player (because it only has one song in its code) and the music doesn't play... understand?
21st Jul 2025, 3:37 AM
Zero
Zero - avatar
0
What I did above is just changing the icon, you can do the music player one! ;)
21st Jul 2025, 3:39 AM
Zero
Zero - avatar
0
Zero Thank you so much !!
21st Jul 2025, 3:47 AM
Manav Roy
Manav Roy - avatar