Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!