₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,179 members, 8,420,674 topics. Date: Friday, 05 June 2026 at 08:44 AM

Toggle theme

What Is Wrong With My SWITCH Statement(javascript) - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingWhat Is Wrong With My SWITCH Statement(javascript) (682 Views)

1 Reply (Go Down)

What Is Wrong With My SWITCH Statement(javascript) by Checked86(op): 9:44am On May 24, 2021
Good morning everyone. I am quite new to programming and I am majoring on HTML, CSS, and JavaScript but sometimes I normally confuse myself by learning php,python and even C.
That is by the way. This my code is not working as want. No matter what I input, it always return the Defualt. Please help guys. These codes below destroyed my night rest.

//my code:


var m;
m =parseInt(prompt("enter any digit of your choice"wink);

switch (m){

case m===1:
alert("you entered one"wink;
break;

case m===2:
alert("you entered two"wink;
break;

default:
alert("unrecognized input"wink;
}
Re: What Is Wrong With My SWITCH Statement(javascript) by Juliusmomoh: 9:47am On May 24, 2021
Just a little error bro
Re: What Is Wrong With My SWITCH Statement(javascript) by Karlebolu(m): 10:03am On May 24, 2021
Change case m === 1 and 2 to just case 1 and case 2 and tell me wetin happen.
Re: What Is Wrong With My SWITCH Statement(javascript) by Checked86(op):
Juliusmomoh:
Just a little error bro
I know it is my fault somewhere,somehow and also could be small error as you said but I have exhausted the little knowledge I have in solving it, but nothing! Please help out
Re: What Is Wrong With My SWITCH Statement(javascript) by Checked86(op): 10:24am On May 24, 2021
Karlebolu:
Change case m === 1 and 2 to just case 1 and case 2 and tell me wetin happen.
I didn't quite get your suggestion. Please come down to my level.
Re: What Is Wrong With My SWITCH Statement(javascript) by exhibit7432(m): 10:36am On May 24, 2021
Checked86:
I didn't quite get your suggestion. Please come down to my level.
Instead of writing “case m ===1”. Just write “case 1”

There whole idea of a switch statement is to check the value of “m” there for different cases so you don’t need to pass them into each case. You only need to state the case
Re: What Is Wrong With My SWITCH Statement(javascript) by Checked86(op): 10:43am On May 24, 2021
exhibit7432:
Instead of writing “case m ===1”. Just write “case 1”

There whole idea of a switch statement is to check the value of “m” there for different cases so you don’t need to pass them into each case. You only need to state the case
It worked. Thanks bros. So I have been over doing it. Thanks a lot.

1 Reply

What Is Wrong With This Line Of Code?Mobile Technology: Lets Build A Mobile App With JavascriptFree HTML5, CSS3 And Basic Javascript (jquery) Training234

Backend Developer Needed AsapHow To Improve Your Data Science SkillsRegex To Get Domain Name From Url