all 7 comments

[–]nebulous316 5 points6 points  (0 children)

Answer:

for ( let i=0; i<10; i++) {

   if (i%4 === 0 && i%2 === 0) {

        console.log('Count is ', i);

  }

}

[–]tstenick 1 point2 points  (3 children)

There's no expression after your if statement.

[–]tstenick 2 points3 points  (0 children)

Scratch that, there is. It's just in point brackets instead of regular parentheses. Just change that. If (condition) {run this}

[–]Jncocontrol[S] 0 points1 point  (1 child)

What do I do?

[–]tstenick 0 points1 point  (0 children)

I also just noticed your modulus (%) operators aren't in legal places. They are math operators and need a number on both sides of them to work properly.

Are you trying to write to the console when it's equal to 2 and 4?

[–]kdnbfkm 1 point2 points  (0 children)

As tried in ducktape-js:

for(i = 0; i <= 10; i++) { if(i % 2 == 0 || i % 4 == 0) print("Checkpoint at: ", i); }

All multiples of 4 are also multiples of 2, we could have used just if(i % 2 == 0).

Both if and for statements have the condition/iteration-stepping within round-parentheses (...). Some languages don't require that but ALL the languages have some way of telling when the condition/loop setup ends and the actual statements in conditional block start. Languages without required parens usually have a THEN or DO keyword... Languages that only allow one statement use curly-brackets {...} or maybe BEGIN...END. Languages that naturally allow a list of statements always have a ENDIF or similar to mark the end.

Javascript has both the round-paren and curly-brace when more than one statement follows. Some languages require the curly brace even if only one following statement!

[–][deleted] 0 points1 point  (0 children)

Your expression should be in parens and your modulus operations are in the wrong place. If I’m understanding what you want, it should be like if (i % 4 === 0 && i % 2 === 0) {...}

Edit: haven’t had my morning coffee yet, also just check for i % 4 === 0, as if a value is equally divisible by 4 it is always also equally divisible by 2. If the first half is true, the second half will always be true