How to divide a variable value and find the remainder?

Okay, so I have a static variable that I want to increase each time a different object is clicked. The first click increases the value by 1, and produces a red square, I want the second click to produce a blue square, the third a red, and continue alternating.

so, is there a way to divide the variable value by 2, and then if the remainder is 1 to produce a blue square, and if 0 produce a red square?

This is how you do it for most languages

var % 2