# Forums

Give help. Get help.

• # December 6, 2012 at 11:24 am

Hi guys and girls

I am just working my way through a Javascript section on Code Academy and I’m really liking it up to now, however I’m stuck on this question;

**The President has notified you that he only wants you to square the ODD numbers between 100 and 150.**

**Add an if…else statement to your for loop block that looks at each number. If it is odd, print the square of the number. Otherwise, just print the number.**

I had this but I think I’m way off;

for (var i = 100; i < = 150; i++) {
var square = i % i;

if (square) {
print (square);
}
else {
print (square)
}
}

# December 6, 2012 at 11:31 am

I think you want to do

if(i % 2) {
print i*i;
}

It checks to see if there’s a remainder from i divided by 2. If there is then i is odd. If it is odd then square it.

# December 6, 2012 at 12:33 pm

@tbwiii

Thanks so much :) I had to amend it a tiny bit but you were right;

for (var i = 100; i < = 150; i++) { if (i % 2) {
print (i * i);
}
else {
print (i);
}

} //End of for statement

# December 6, 2012 at 2:19 pm

Sorry! I was on my phone at the time or I would have typed the whole solution out :)

# December 6, 2012 at 3:13 pm

It’s okay :) you gave me what I needed really. Helped me get more used to the syntax adding the brackets etc. Really liking this JavaScript atm

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.