+ 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

12th Dec 2017, 7:16 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
14 Antworten
+ 2
coz your input is a string type If you do like this it'll work case "1": case "2": etc
12th Dec 2017, 7:22 PM
MuzzRK
MuzzRK - avatar
+ 8
Placing the parseInt in this code again generated the previous problem....it goes for default switch !!
12th Dec 2017, 7:48 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 7
yes it worked .. thnx
12th Dec 2017, 8:15 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 7
Well you are from where??
12th Dec 2017, 8:15 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 7
India....Its 1:47am here😁😀
12th Dec 2017, 8:17 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 7
@Fares Thnx
2nd Jan 2018, 5:05 AM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 6
Ohhh....well i have used parseInt in my calculator once .... 😀😁 ...btw thnx...🙏🙏
12th Dec 2017, 7:46 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 5
Ohhh...i got that ....Thnx @MuzzRK
12th Dec 2017, 7:32 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 5
No.....i m new in js...but how to do??😁
12th Dec 2017, 7:39 PM
A N S H U L S I N G H
A N S H U L   S I N G H - avatar
+ 1
well I looked it up parseInt(prompt());
12th Dec 2017, 7:43 PM
MuzzRK
MuzzRK - avatar
+ 1
just remove quotes " " your day type is int and case check - string type. you need them both to be of the same type
12th Dec 2017, 8:10 PM
MuzzRK
MuzzRK - avatar
+ 1
Russia, you?
12th Dec 2017, 8:16 PM
MuzzRK
MuzzRK - avatar
+ 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.
1st Jan 2018, 11:25 PM
Fares Younis
Fares Younis - avatar
0
you can also just change the type of input to int, dunno how to do it in JS though xD
12th Dec 2017, 7:36 PM
MuzzRK
MuzzRK - avatar