+ 1

Why this code doesn't work?

var In = t; switch (In) { case a: break; document.write("t"); case t: document.write("e"); break; default: document.write ("Not recognized"); }

7th Apr 2018, 4:19 PM
Filip Novotný
Filip Novotný - avatar
8 ответов
+ 8
Then you should keep "a" and "t" in double quotes.
7th Apr 2018, 4:25 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 7
Wait, i saw your profile. You mean this code ? https://code.sololearn.com/ctFrcH4nF2eK/?ref=app The code type is Java not JavaScript and your code is in JavaScript. Create a web code and put this code in its JS section.
7th Apr 2018, 4:31 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 6
What is In ? What is t ? What is a ?
7th Apr 2018, 4:22 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 6
Because if you won't put double quotes then it would be treated as a variable and if you will then it will be treated as a String (text)
7th Apr 2018, 4:29 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 1
In is a variable defined upper. t and a are possible values of variable In
7th Apr 2018, 4:24 PM
Filip Novotný
Filip Novotný - avatar
+ 1
why? you think? I can try it. Might you're right
7th Apr 2018, 4:27 PM
Filip Novotný
Filip Novotný - avatar
+ 1
var In = "t"; switch (In) { case "a": break; document.write("t"); case "t": document.write("e"); break; default: document.write ("Not recognized"); } still it doesn't work :(
7th Apr 2018, 4:29 PM
Filip Novotný
Filip Novotný - avatar
+ 1
now it works. thx for help
7th Apr 2018, 4:35 PM
Filip Novotný
Filip Novotný - avatar