Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Random sound Player

I'm trying to make it so that every 3 minutes, a new song gets played... but its not working and i'm not sure why... heres my code,

window.onload = function(){
  song();
  setInterval(song, 180000);
}

var song1 = new Audio("music/song1.mp3");
var song2 = new Audio("music/song2.mp3");
var song3 = new Audio("music/song3.mp3");
var song4 = new Audio("music/song4.mp3");
var song5 = new Audio("music/song5.mp3");
var song6 = new Audio("music/song6.mp3");
var song7 = new Audio("music/song7.mp3");
var song8 = new Audio("music/song8.mp3");
var songNum = 1;

function song(){
  songNum = Math.floor(Math.random() * 8) + 1;
  if(songNum == 1){
    song1.load();
    song1.play();
  } else if(songNum == 2){
    song2.load();
    song2.play();
  } else if(songNum == 3){
    song3.load();
    song3.play();
  } else if(songNum == 4){
    song4.load();
    song4.play();
  } else if(songNum == 5){
    song5.load();
    song5.play();
  } else if(songNum == 6){
    song6.load();
    song6.play();
  } else if(songNum == 7){
    song7.load();
    song7.play();
  } else if(songNum == 8){
    song8.load();
    song8.play();
  }
}

I've tried to change many things but I can't figure out whats causing the issue, it seems to work sometimes but then I leave and go back into the page and it doesn't work. If you know the issue please help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found the issue, for anyone who has a similar issue I will leave this comment up with the answer... The issue was that it was calling the function before the user interacted with the site, so all I did was make it call after the 'click to continue' page that i had setup as a tutorial

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!