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

294
Views
¿Cómo puedo imprimir oraciones en un tiempo elegido?

soy un novato en js xd, ¡quiero poner un texto en un html en un tiempo elegido de un reloj! quiero que imprima "pide un deseo" cuando sean las 11:11 el código:

 function startTime() { const today = new Date(); let h = today.getHours(); let m = today.getMinutes(); let s = today.getSeconds(); m = checkTime(m); s = checkTime(s); document.getElementById('txt').innerHTML = h + ":" + m + ":" + s; setTimeout(startTime, 1000); } function checkTime(i) { if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10 return i; }

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

0

Esto se puede hacer a través de setInterval en javascript con algunas comprobaciones básicas de condición.

Primero cree un objeto de fecha a través de new Date() , luego obtenga horas y minutos, verifique si la hora y el minuto son iguales a su tiempo especificado y luego imprima el valor.

Necesitamos establecer un intervalo de 60 segundos que es igual a 60.000 milisegundos para no volver a imprimir el mismo valor en ese minuto.

Puedes probar esto -

 setInterval(function(){ var date = new Date(); if(date.getHours() === 11 && date.getMinutes() === 11){ console.log("make a wish"); } }, 60000);
about 4 years ago · Juan Pablo Isaza Report

0

Algo como esto servirá.

 function startTime() { const today = new Date(); let h = today.getHours(); let m = today.getMinutes(); let s = today.getSeconds(); m = checkTime(m); s = checkTime(s); document.getElementById('txt').innerHTML = h + ":" + m + ":" + s; if (h == 11 && m == 11) { console.log("Make a wish"); } else { setTimeout(startTime, 1000); } } function checkTime(i) { if (i < 10) { i = "0" + i }; // add zero in front of numbers < 10 return i; } startTime();
 <p id="txt"></p>

about 4 years ago · Juan Pablo Isaza Report

0

Use la función de devolución de llamada de SetInterval y obtenga la hora actual. después puedes comprobar si son las 11:11. Si tiene éxito, no olvide borrar el intervalo.

 const innterval = setInterval(function () { check() }, 5000); function check() { var today = new Date(); var t1111 = today.getHours() + ':' + today.getMinutes(); if (t1111 === '11:11') { alert('11:11') document.getElementById('txt').innerHTML = t111 + ' PARTY!' clearInterval(innterval); } console.log('Current time: ' + t1111 + ' still Waiting') }
 <div id="txt"></div>

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!