0

Confused

Can somebody please explain to me why the output is 12 for this example. I can’t understand why it wouldn’t be 1? Var sub = “Eng”; Switch (sub) { Case “Eng”: Document.write (1) Case “Es”: Document write (2)

14th Feb 2019, 6:41 PM
Luke Sandford
2 Answers
+ 1
thanks for the response, it was actually one of the questions i was asked in the challenges that I got wrong. The question that was asked was what is the output of this code? I answered 1 but the correct answer is 12 I just didnt understand why the second case “Es” part of the statement was executed?
14th Feb 2019, 7:10 PM
Luke Sandford
0
https://www.sololearn.com/learn/JavaScript/1139/?ref=app It is the logic of the switch statement. Var sub = “Eng”; Switch (sub) { Case “Eng”: Document.write (1) break; //print 1, jump out of the switch statement Case “Es”: Document write (2) break; //not really necessary for the last case Without the break statement all the cases are processed. In your example: Document write (2)
14th Feb 2019, 11:51 PM
Denise Roßberg
Denise Roßberg - avatar