Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda