Estoy haciendo un ejercicio y no puedo ver el reloj digital que he insertado en el código.
Por favor, me pueden ayudar?.
Muchas gracias.
function mostrarSaludo(){
var fecha = new Date();
var hora = fecha.getHours();
if(hora >= 0 && hora < 12){
texto = "Buenos Días";
imagen = "img/mañana.png";
}
if(hora >= 12 && hora < 18){
texto = "Buenas Tardes";
imagen = "img/tarde.png";
}
if(hora >= 18 && hora < 24){
texto = "Buenas Noches";
imagen = "img/noche.png";
}
document.images["tiempo"].src = imagen;
document.getElementById('txtsaludo').innerHTML = texto;
}
function startTime(){
var hoy = new Date();
var h = hoy.getHours();
var m = hoy.getMinutes();
var s = hoy.getSeconds();
h= checkTime(h);
m= checkTime(m);
s= checkTime(s);
document.getElementById('txt').innerHTML =(""+ h + ":" + m + ":" + s);
console.log(h + ":" + m + ":" + s +"");
setInterval(startTime(), 1000);
//setInterval(start, 1000);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // añade cero delante en los numeros < 10
return i;
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Ventana</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body class="w3-container w3-center" onload="mostrarSaludo()">
<div onclick="startTime()">
<p id="txt">Reloj:</p>
</div>
<div>
<div id="saludo" class="">
<img class="" name="tiempo">
<div id="txtsaludo"></div>
</div>
</div>
<script type="text/javascript" src="js/ventana.js"></script>
</body>
</html>