0

Can anyone explain that answer please?

Var x=0 , y=0; for( i=0 ; i <= 2; i++ ) {x = i ; switch(x) {case 0: y = 100 ; case 1: y+= 10 ; case 2 : y+= 1} } console.log(y)

24th Apr 2020, 2:29 AM
Ibrahim Idrees
Ibrahim Idrees - avatar
3 Answers
+ 1
1 - declares the variable var x = 0, y = 0 2 - iterates through the loop as long as i is 2 for ( i = 0; i<=2; i++){ 3 - Now x has the same value of i x = i 4 - Init switch case switch(x) // for x { case 0: y = 100; // if x is 0 then y is 100 case 1: y = 10 // if x is 1 then 10 is added to y case 2: y = 1 // if x is 2 then add 1 to y } console.log(y) //output 123 The switch case goes futher, as long as the statement is true, in the other case statement, because there 's no break keryword. Therefore the output is 123
24th Apr 2020, 8:53 AM
Abdoul Hakim
Abdoul Hakim - avatar
- 1
What is the answer m
24th Apr 2020, 8:17 AM
Abhay
Abhay - avatar
- 1
What is the answer ?
24th Apr 2020, 8:17 AM
Abhay
Abhay - avatar