Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,421 members, 7,815,952 topics. Date: Thursday, 02 May 2024 at 10:00 PM

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

Nairaland Forum / Science/Technology / Programming / What Is Wrong With My SWITCH Statement(javascript) (488 Views)

Da Fuk Is Wrong With This Board? Useless Threads Everywhere!! / The Switch Statement Is Redundant / After 10days Of Coding With Html, Css And Javascript Forum4africa Is Ready (2) (3) (4)

(1) (Reply) (Go Down)

What Is Wrong With My SWITCH Statement(javascript) by Checked86: 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: 10:18am On May 24, 2021
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: 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

3 Likes 2 Shares

Re: What Is Wrong With My SWITCH Statement(javascript) by Checked86: 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)

Please Help Me With Something To Eat to cool me off suicidal thoughts / Where Can I Learn Programming On Sundays At Ikotun / HELP,my folders have arrows

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.