i am having problems understanding the switch statement any explanation on it would be welcomed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

i am having problems understanding the switch statement any explanation on it would be welcomed

25th Aug 2019, 10:57 PM
jeffrey ogbonnaya
jeffrey ogbonnaya - avatar
3 Answers
+ 1
Hope this code helps you a bit: https://code.sololearn.com/cCik5HuXBBmd/?ref=app
25th Aug 2019, 11:45 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
A switch statement in its simplest terms is just a bunch of else if statements together. To make it neater and more flexible (for longer scripts) a switch statement would be used. An example is Var I = 6; If (I == 3) { Console.write("true"); } else if (I == 6) { Console.write("true"); } Else { Console.write("false"); //outputs true In a switch statement that code would look like this: Var I = 6; Switch(I) { Case 3: Console.write("true"); Break; Case 6: Console.write("true"); Break; Default: Console.write("false"); } //outputs false. You can look at a switch statement program in the js tab here https://code.sololearn.com/WoAnpnUWf6sf/?ref=app
25th Aug 2019, 11:21 PM
Minerals2016
Minerals2016 - avatar
+ 1
https://www.sololearn.com/learn/JavaScript/1139/
25th Aug 2019, 11:14 PM
Dlite
Dlite - avatar