+ 1

Javascript switch statement

function main() { var themeNumber = parseInt(readLine(), 10); /* 1 - Light 2 - Dark 3 - Nocturne 4 - Terminal 5 - Indigo */ // Your code here switch(themeNumber) case 1: console.log("Light"); break; case 2: console.log("Dark"); break; case 3: console.log("Nocturne"); break; case 4: console.log("Terminal"); break; case 5: console.log("Indigo"); break; } Where is the error in the above program

18th Sep 2021, 11:01 AM
Rabiya Tayyab
Rabiya Tayyab - avatar
4 Réponses
+ 2
I have seen with the brackets immediately so but still tested in SL Playground. And yes I knew it, that works. Happy coding!
19th Sep 2021, 10:42 AM
JaScript
JaScript - avatar
+ 5
You need Brackets Rabiya Tayyab switch(themeNumber){ … }
18th Sep 2021, 11:13 AM
JaScript
JaScript - avatar
+ 1
Yeah you have written everything omin one block after switch case you need to put bracket till end of your all cases . using default is also a good practice if your case will not work then default statement will execute
18th Sep 2021, 12:34 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
JaScript & A.S. thanks both of you.. Its works
19th Sep 2021, 3:27 AM
Rabiya Tayyab
Rabiya Tayyab - avatar