+ 2

How it's working?

var sum=0; for (var i = 1; i <=5; i++) { if (i==1) continue; if (i>3) break; sum+=i; } document.write(sum)

1st May 2017, 8:29 PM
Kristina Hakobyan
Kristina Hakobyan - avatar
8 Antworten
+ 3
You're thinking right ☺
1st May 2017, 8:53 PM
Ghauth Christians
Ghauth Christians - avatar
+ 4
I like the fact that you're curious to play around with your codes to see what the output will be when you run the code with errors @Kristina Hakobyan ☺ Usually what I expect to happen when a Javascript code has syntax errors, the code just doesn't simply run but in this case you're just getting an "unexpected result" and that's all there is to it I believe. ☺
1st May 2017, 8:38 PM
Ghauth Christians
Ghauth Christians - avatar
+ 3
but I answer 5 here it's accept wrong answer 😂😂😂😁
1st May 2017, 8:45 PM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 3
lol I want to know I'm thinking right or wrong because it's important for me lol 😁 thx for support me to understand it
1st May 2017, 8:51 PM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 3
thx thx thx thx thx 👍👍👍👍👍🤗🤗🤗👏👏👏👏😊😊😊😊😉😉😉😉
1st May 2017, 8:54 PM
Kristina Hakobyan
Kristina Hakobyan - avatar
+ 2
Well I believe that your loop executes still be ignores the if statements and then assigns it's final value, which is 5, to sum at the end of the loop and then prints it.
1st May 2017, 8:42 PM
Ghauth Christians
Ghauth Christians - avatar
+ 2
Lol well play around with it but if you want a specific result but you don't get what you want then feel free to ask for my help and then I'll help you get the result you want. 😉
1st May 2017, 8:49 PM
Ghauth Christians
Ghauth Christians - avatar
+ 1
thx so much but I only what to understand how it's working have a logics
1st May 2017, 8:41 PM
Kristina Hakobyan
Kristina Hakobyan - avatar