Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
The button has no operation. How to use the switch as a function

I just started learning javascript and this is my first problem. I tried this method but it did not work. Please advise how I can use the switch as a function in events. Thanks in advance for your guidance

function lbl() {
      switch (new Date().getDate()) {
            case 0: {
                  document.getElementById('show').innerHTML = "sunday";
                  break;
            }
            case 1: {
                  document.getElementById('show').innerHTML = "monday";
                  break;
            }
            case 2: {
                  document.getElementById('show').innerHTML = "tuesday";
                  break;
            }
            case 3: {
                  document.getElementById('show').innerHTML = "wednesday";
                  break;
            }
            case 4: {
                  document.getElementById('show').innerHTML = "thursday";
                  break;
            }
            case 5: {
                  document.getElementById('show').innerHTML = "friday";
                  break;
            }
            case 6: {
                  document.getElementById('show').innerHTML = "saturday";
                  break;
            }
      }
}
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width= auto, initial-scale=1.0">
      <title>Document</title>
</head>
<body>
      <h1 id="show">show date! </h1>
      <button onclick=lbl()>click me!</button>
      <script src="js.js"></script>
</body>
</html>

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The getDate() method returns the day of the month (from 1 to 31).

The getDay() method returns the day of the week (from 0 to 6) for the specified date.

Just switch getDate() to getDay() and your code will work

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda