# Javascript Flow Control Excercise 8 issue

**URL:** <https://forum.codewithmosh.com/t/javascript-flow-control-excercise-8-issue/18810>\
**Category:** JavaScript\
**Created:** [March 15, 2023, 7:05pm UTC](https://forum.codewithmosh.com/t/javascript-flow-control-excercise-8-issue/18810 "2023-03-15T19:05:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fchepil](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@fchepil](https://forum.codewithmosh.com/u/fchepil)\
**Post date:** [March 15, 2023, 7:05pm UTC](https://forum.codewithmosh.com/t/javascript-flow-control-excercise-8-issue/18810/1 "2023-03-15T19:05:20Z")

</div>

I cannot get the same results as Mosh with the identical code. It seems the if statement is being ignored. Below is code with added console.log lines that helped me understand what is failing. The question is why is the 'if statement" failing?

"console.log(sumLimits(7));

function sumLimits(limit) {  
let sum = 0;

```
for (let i = 0; i <= limit; i++) {
    if ((i % 3 === 0) || (i % 5 === 0))
        console.log(i)
		sum += i
		console.log('sum ', sum);
}

return sum;

```

}  
"

Output to Console is as follows:  
"  
[Running] node “e:\Java-Node\lessons-sumlimit.js”

0  
sum 0  
sum 1  
sum 3  
3  
sum 6  
sum 10  
5  
sum 15  
6  
sum 21  
sum 28  
28  
"

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [March 17, 2023, 8:03am UTC](https://forum.codewithmosh.com/t/javascript-flow-control-excercise-8-issue/18810/2 "2023-03-17T08:03:06Z")

</div>

Since you don’t refere to a lesson or say what result you would expect I can only guess from your indentation that you want the sum statements to be executed in the `true` branch of the second `if`. If so, you need to wrap the three lines below the `if` with curly brackets for them to be treated as a code block. Currently only `console.log(i)` gets executed if the condition of the `if` statement is true. The addition and the second log are executed unconditionally since they are outside the if statement. You can easily see that when you let your IDE reformat the code to reflect the logical structure.

---

<div class="post-metadata">

**Author:** ![fchepil](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@fchepil](https://forum.codewithmosh.com/u/fchepil)\
**Post date:** [March 17, 2023, 2:26pm UTC](https://forum.codewithmosh.com/t/javascript-flow-control-excercise-8-issue/18810/3 "2023-03-17T14:26:47Z")

</div>

Hi Sam,

Lesson # was truncated from title!

VS code was altering format of code, and being a Noob to JS, I missed the requirement of { } to keep code treated as a block.

Thanks for the assistance!!

Fausto
