+ 6
Can anyone make me understand the Switch In Js??
Every time i input 1, 2 ,3 it always shows the default case...Why it ia so?? https://code.sololearn.com/WNJ0fk8VCOb2/?ref=app
14 Antworten
+ 2
coz your input is a string type
If you do like this it'll work
case "1":
case "2":
etc
+ 8
Placing the parseInt in this code again generated the previous problem....it goes for default switch !!
+ 7
yes it worked .. thnx
+ 7
Well you are from where??
+ 7
India....Its 1:47am here😁😀
+ 7
@Fares Thnx
+ 6
Ohhh....well i have used parseInt in my calculator once .... 😀😁 ...btw thnx...🙏🙏
+ 5
Ohhh...i got that ....Thnx @MuzzRK
+ 5
No.....i m new in js...but how to do??😁
+ 1
well I looked it up
parseInt(prompt());
+ 1
just remove quotes " "
your day type is int and case check - string type. you need them both to be of the same type
+ 1
Russia, you?
+ 1
If you would like to see useful example of switch statement;
Check out this code: https://code.sololearn.com/Wm1sEpVi20wl/#
just read the comment in the code and shall understand.
0
you can also just change the type of input to int, dunno how to do it in JS though xD