I'm creating a small horror game and I can't seem to figure out how to add background music in javascript.
I looked up how to add it and I found a solution on w3schools, but when I tried it out, it didn't work. I'm trying to play the sound called backgroundMusic which is set to an mp3 file called bgmusic.mp3
var jumpscare;
var backgroundMusic;
music();
function music() {
jumpscare = new sound("jumpscare.mp3");
backgroundMusic = new sound("bgmusic.mp3");
backgroundMusic.play();
}
What I'm hoping to happen is for the music to start playing when I open the application.