JSFiddle - React, Tailwind, and code Playground

by Manuel Gertrudix

HTML

<!DOCTYPE html>
<html>
<body>

  <p>Haz clic en el botón para obtener un saludo que se adapta a la hora del día:</p>

<button onclick="myFunction()">Saludame según la hora del día</button>

<p id="saludando"></p>

<script>
function myFunction() {
    var saludo;
    var time = new Date().getHours();
    if (time < 12) {
        saludo = "Buenos días";
    } else if (time < 18) {
        saludo = "Buenas tardes";
    } else {
        saludo = "Buenas noches";
    }
document.getElementById("saludando").innerHTML = saludo;
}
</script>

</body>
</html>