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

86
Vistas
Cannot access "audio" before initialization in js problem at line 2

Made a clock and alarm a while back and was going to maybe add some more and now the clock is no longer displaying. Problem possibly around line 2 (Learning to code I know its probably something simple) The error code I get back is just the initialization of the audio saying that it is unable to access even though it's in the same file

    '''

const display = document.getElementById('clock');
const audio = new audio('finAlarm.wav');
audio.loop = true;
let alarmTime = null;
let alarmTimeout = null;

function updateTime() {
const date = new Date();

const hour = formatTime(date.getHours());
const minutes = formatTime(date.getMinutes());
const seconds = formatTime(date.getSeconds());



display.innerText=`${hour} : ${minutes} : ${seconds}`
}

function formatTime(time) {
if ( time < 10 ) {
    return '0' + time;
}
return time;
}

function setAlarmTime(value) {
alarmTime = value;
}

function setAlarm() {
if(alarmTime) {
    const current = new Date();
    const timeToAlarm = new Date(alarmTime);

    if (timeToAlarm > current) {
        const timeout = timeToAlarm.getTime() - current.getTime();
        alarmTimeout = setTimeout(() => audio.play(), timeout);
        alert('Alarm set');
    }
}
}

function clearAlarm() {
var name = prompt("are you up?>:)")
if (name ==null || name=="") {
txt = "incorrect >:(|)"
} else {
    audio.pause();
    audio.currentTime = 0;
    alert('Alarm Stopped')
     }
     alert(txt);
     audio.pause();
audio.currentTime = 0;
if (alarmTimeout) {
    clearTimeout(alarmTimeout);
    alert('Alarm Stopped');
}
}

setInterval(updateTime, 1000);

    '''
about 4 years ago · Juan Pablo Isaza
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