Answer 8 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Answer 8

Why is the answer is 8? I can’t see any principles

25th Aug 2018, 7:45 PM
Hayk Ghazakhyan
Hayk Ghazakhyan - avatar
3 Answers
+ 3
For what question was the answer 8?
25th Aug 2018, 7:50 PM
Russ
Russ - avatar
+ 3
switch (x) means that every case is compared with the value of x. In this example, cases 1 & 2 are not carried out because x is not equal to either 1 or 2 (since it is equal to 3). The default case is carried out when none of the other cases are carried out, which is true in this example. The default case prints the value of x plus 5, which, as x is 3, 3+5 = 8. So that is why it returns 8.
25th Aug 2018, 8:34 PM
Russ
Russ - avatar
0
var x=3 switch (x) { case 1: document.write(x); break; case 2: document.write(x+2); break; default: document.write(x+5); } the answer is 8
25th Aug 2018, 8:14 PM
Hayk Ghazakhyan
Hayk Ghazakhyan - avatar