+ 1

Can't understand why 12?

var a =0; for(k=1;K<=2;K=k+1){ for(i=0;i<=5;i++){} a++; alert(a)}

9th May 2017, 8:23 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
33 odpowiedzi
+ 1
yes but he started with I=0 so the different values of I are : 0 1 2 3 4 5 break so 6 values don't forget to leave a like 😁👍
9th May 2017, 8:43 AM
Hbeo
Hbeo - avatar
+ 1
but why 2*6 my second loop break when I=5
9th May 2017, 8:41 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
@Kristina Your code is not quite correct to get answer 12. K variable is not same as k variable. Second iteration i is do nothing (empty bracket). The code can get output 12 is var a =0; for(k=1;k<=2;k=k+1){ for(i=0;i<=5;i++){ a++;} } alert(a); // a has increment for 12 times (2 × 6)
9th May 2017, 8:44 AM
Calviղ
Calviղ - avatar
+ 1
that code I meet here in challenge
9th May 2017, 8:46 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
how
9th May 2017, 8:54 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
go To view correct answers, go to your code and click on the bottom who is on the right top corner if I was helpful don't forget to leave a like on my comments 👍😁
9th May 2017, 9:04 AM
Hbeo
Hbeo - avatar
+ 1
like
9th May 2017, 9:19 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
lav
9th May 2017, 9:42 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
of course
9th May 2017, 10:09 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
voch der
9th May 2017, 10:41 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
Learjavascript karda
9th May 2017, 10:48 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
ruseren
9th May 2017, 10:50 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
Facebook kristina Hakobyan
9th May 2017, 11:10 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
inchu
11th May 2017, 8:18 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 1
DE harc ches tve js ic
11th May 2017, 8:59 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
0
Are you sure that the second } is before a++ ?
9th May 2017, 8:30 AM
Hbeo
Hbeo - avatar
0
I think yes why?
9th May 2017, 8:31 AM
Kristina Hakobyan
Kristina Hakobyan - avatar
0
because if it's before a=2 and if it's after a=12
9th May 2017, 8:32 AM
Hbeo
Hbeo - avatar
0
if it's after is 12 while you do : 2x6 a++
9th May 2017, 8:34 AM
Hbeo
Hbeo - avatar