I've written the code below, but it's not working properly! When I click on the play button, nothing happens
HTML:
<button id="play"><img id="playicon" src="img/Polygon 1.svg"></button>
JS: I have a variable named 'song0' for sound, and it's supposed to play or pause in the 'playPauseEvent' function. However, it doesn't perform as expected. I found this method on the following site
var playpause, play1icon, song0;
function aslekar(){
song0 = new Audio('audio/Meydoon.mp3');
song0.loop = true;
song0.play();
document.getElementById("moon");
play1icon = document.getElementById("playicon");
playpause = document.getElementById("play");
playpause.addEventListener("click", playPauseEvent);
function playPauseEvent(){
if(song0.paused){
song0.play();
play1icon.setAttribute("src", "img/Polygon 1.svg");
}else{
song0.pause();
play1icon.setAttribute("src", "img/Group 1.svg");
}
}
}
window.addEventListener("load", aslekar);
I am very new to coding and would appreciate any help with this :)