Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda