I NEED HELP!!!! Js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I NEED HELP!!!! Js

Why when i press on button music dont stop playing? https://code.sololearn.com/Wp7OFZ9YeLLu/?ref=app

10th Sep 2017, 7:29 PM
Ferrum
Ferrum - avatar
3 Answers
+ 3
If you move your these two lines into the window.onload function, it should work out. var mySong = new Audio(); mySong.src ="..."; The way it's running right now, you're redefining mySong every time you click the button, so it can't pause it, and every other time the button is clicked a new instance of the song will start playing (on top of what's already playing). By moving these two lines into the window.onload function, the song is defined once, and the pause function can work properly. Hope this helps! Final code here: https://code.sololearn.com/W13nmxDgVa4r/#html
10th Sep 2017, 7:43 PM
Kenny
Kenny - avatar
0
thanksss!! even stackoverflow cant help me!!! you are best!!
10th Sep 2017, 7:47 PM
Ferrum
Ferrum - avatar
0
Happy to help :)
10th Sep 2017, 8:35 PM
Kenny
Kenny - avatar