lundi 18 janvier 2021

Create new text at specific time

Does anyone have a solution to my problem? I am kind of desperate already.

Is there a way to create a random number at a specific time? For example on Monday at 7.30am "number1" should be shown. On Monday 8.30 "number2" should be shown. On Monday at 9.30 "number3" should be shown.

All I found is https://www.askdavetaylor.com/can_i_change_my_web_page_based_on_time_of_day/ but I can't make it work for my problem.

Thanks in advance.

I cant make the minute part work.

<script type="text/javascript">
var thedate   = new Date();
var dayofweek = thedate.getUTCDay();
var hourofday = thedate.getUTCHours();
var minutesday = thedate.getMinutes();
    
    
function Stunde1()
{
// return TRUE if it's Mon through Sat, 3a-6a UTC
if (dayofweek != 2 && (hourofday >7 && hourofday <8) && (minutesday >31) ) 
{ return true;}
return false; }
    
function Stunde2()
{
// return TRUE if it's Mon through Sat, 3a-6a UTC
if (dayofweek != 2 && (hourofday > 7 && hourofday < 9) && (minutesday >31) ) 
{ return true;}
return false; }
    
function Stunde3()
{
// return TRUE if it's Mon through Sat, 3a-6a UTC
if (dayofweek != 2 && hourofday > 9 && minutesday >30 && hourofday <11 ) 
{ return true;}
return false; }
    
function Stunde4()
{
// return TRUE if it's Mon through Sat, 3a-6a UTC
if (dayofweek != 2 && (hourofday > 11 && hourofday < 13) && (minutesday <31) ) 
{ return true;}
return false; }
</script>



<script type="text/javascript">
if (Stunde1()) { document.write("<h2>Stunde1</h2>");} 
else if (Stunde2()) { document.write("<h2>Stunde2</h2>");} 
else if (Stunde3()) { document.write("<h2>Stunde3</h2>");} 
else if (Stunde4()) { document.write("<h2>Stunde4</h2>");} 
else {
document.write("<h2>kaputt</h2>");
}
</script>



Aucun commentaire:

Enregistrer un commentaire