Confused | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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