A última linha

Olá pessoal.

O script abaixo funciona redondinho até a penultima linha de cada dia da semana.
A última não vai nem por decreto.
Se alguém puder ajudar, agradeço.


<script>
function rodarImagens(){
        var now = new Date();
        var agora = now.getDay();
        var hora = now.getHours();
        switch (agora){
        
                case 0: //domingo
                        if(hora >= 0 && hora < 6){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 6 && hora < 23){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 23 && hora < 0){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}

                break
                case 1: //segunda
                        if(hora >= 0 && hora < 6){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 6 && hora < 9){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 9 && hora < 18){ document.write('<iframe src="7 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 18 && hora < 23){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 23 && hora < 0){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}

                break
                case 2: //terça                
                        if(hora >= 0 && hora < 6){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 6 && hora < 9){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 9 && hora < 18){ document.write('<iframe src="7 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 18 && hora < 23){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 23 && hora < 0){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}

                break
                case 3: //quarta
                        if(hora >= 0 && hora < 6){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 6 && hora < 9){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 9 && hora < 18){ document.write('<iframe src="7 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 18 && hora < 23){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 23 && hora < 0){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}

                break
                case 4: //quinta
                        if(hora >= 0 && hora < 6){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 6 && hora < 9){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 9 && hora < 18){ document.write('<iframe src="7 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 18 && hora < 23){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 23 && hora < 0){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}

                break
                case 5: //sexta
                        if(hora >= 0 && hora < 6){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 6 && hora < 9){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 9 && hora < 18){ document.write('<iframe src="7 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 18 && hora < 23){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 23 && hora < 0){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                break
                case 6: //sábado
                        if(hora >= 0 && hora < 6){ document.write('<iframe src="0 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 6 && hora < 9){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 9 && hora < 13){ document.write('<iframe src="7 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 13 && hora < 23){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}
                        if(hora >= 23 && hora < 0){ document.write('<iframe src="6 hs.html" style="position:absolute; left:0px; top:0px; z-index:14" frameBorder=0 width=120 height=70 allowTransparency>');}

                break
        }
}

</script>
</body>

<p>&lt;script&gt;rodarImagens();&lt;/script&gt;</p>

Olá, vinheteiro.

o erro se da quando você faz esse teste…

hora >= 23 && hora < 0

ou seja, esse teste nunca será “true”… pois hora nunca é maior que 23 e menor que 0 ( -1, -2, -3)…

substitua por apenas…

hora >= 23

que vai dar certo…

Grande abraço, e sucesso.

Sucesso sim. Graças a sua dica.
Astucia e boa vontade.
O sucesso é teu!

Que ótimo entao.
Sucesso.

Será que tem como eu controlar por minutos também ???

Objetos Date tem um método getMinutes também.
Basta basear sua lógica nele.

Agora um conselho: Você está criando um monstro.
Veja quanta repetição de código tem no seu script.

Pelo que reparei por cima:

  • Todos dias da semana seguem a mesma regra, mas há um case para cara.
  • O método document.write é chamado de forma MUITO parecida (tão parecida que a variação poderia ser apenas parâmetros)
  • Você poderia fazer uma tabela associatiava entre horas-minutos e o valor do parâmetro do tópico acima

Pense com carinho nisso, vai ficar muito mais fácil mexer nesse código.

Como se daria tal ?

Eu preciso alterar cada 10 minutos. Se alguem puder ajudar, serei grato.