What Is Wrong With My SWITCH Statement(javascript) - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › What Is Wrong With My SWITCH Statement(javascript) (681 Views)
| 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" );switch (m){ case m===1: alert("you entered one" ;break; case m===2: alert("you entered two" ;break; default: alert("unrecognized input" ;} |
| 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): 10:18am On May 24, 2021*. Modified: 10:48am On May 24, 2021 |
Juliusmomoh: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: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: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:It worked. Thanks bros. So I have been over doing it. Thanks a lot.
|
What Is Wrong With This Line Of Code? • Mobile Technology: Lets Build A Mobile App With Javascript • Free HTML5, CSS3 And Basic Javascript (jquery) Training • 2 • 3 • 4
Rate My Music Player With Node Js • Pepakura Designer - Windows PC • Check Out My Tesla Homepage With Slick Animations Using React JS
);