Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7706113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:02:11+00:00 2026-06-01T00:02:11+00:00

Im learning javascript, and I am struggling to get my case statement to work.

  • 0

Im learning javascript, and I am struggling to get my case statement to work. The idea is that you enter any number between 1 – 7 in the form it will invoke a function and it will alert giving you the day of the week. The default is “not a valid day”. It seems really simple but I thought I had done it right, I have a feeling its a variable problem……

function DayOfTheWeek()

var 1 = DayOfTheWeek;
var 2 = DayOfTheWeek;
var 3 = DayOfTheWeek;
var 4 = DayOfTheWeek;
var 5 = DayOfTheWeek;
var 6 = DayOfTheWeek;
var 7 = DayOfTheWeek;


switch (DayOfTheWeek){
case '1':
alert ("It's Monday");
break;

case 2:
alert ("It's Tuesday");
break;

case 3:
alert ("It's Wednsday");
break;

case 4:
alert ("It's Thursday");
break;

case 5:
alert ("It's Friday");
break;

case 6:
alert ("It's Saturday");
break;

case 7:
alert ("It's Sunday");
break;

default:
alert ("Not a valid day");
break;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:02:12+00:00Added an answer on June 1, 2026 at 12:02 am

    Nearly all of your code is wrong.

    Your forgot the { after the function is defined and the } at the end of the function. You want to use give a variable the same name like the function (it seems that you want to do this).

    A variable name can’t start with a number.

    What you want could be:

        function DayOfTheWeek(day) {
            switch(day){
                case 1:
                    alert ("It's Monday");
                break;
                case 2:
                    alert ("It's Tuesday");
                break;
    
                case 3:
                    alert ("It's Wednsday");
                break;
    
                case 4:
                    alert ("It's Thursday");
                break;
    
                case 5:
                    alert ("It's Friday");
                break;
    
                case 6:
                    alert ("It's Saturday");
                break;
    
                case 7:
                    alert ("It's Sunday");
                break;
    
                default:
                    alert ("Not a valid day");
                break;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Javascript via an online tutorial, but nowhere on that website or any
I'm starting learning javascript for a project, I've found a script that does a
I'm just learning JavaScript right now, so please do try and explain with that
I have just started learning Javascript and I am absolutely overwhelmed with the number
Im just learning javascript and I'm just wondering why this doesn't work. I've created
I am just learning Javascript and I am trying to create a script that
I'm learning javascript and i want to experiment with innerHTML. I see that the
I am learning to write javascript and Chrome extensions. I want an extension that
Is it a good idea to learn JavaScript before learning a JavaScript framework library
I'm learning JavaScript and heard that document.getElementbyId() is quite useful. So, I thought that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.