1) first syntax mistake in “If”. This is reserved JS word, you always need to write it in small letters “if”
2) “+239” “+305”. It’s not critical, but when the number is positive, you don’t need to place “+”, just “239” “305”
3) we can’t get a number that will be less than 239 and bigger than 305. As option we could use OR operator ||
if (r < 239 || r > 305)
or swap signs
if (r > 239 && r < 305)
4) for colors, by default, we use an array with 4 numbers [0,0,0,0] where the first 3 number is R(red)G(green)B(blue). To use hex code we need to use the special function hexToRgb(). And we don’t need to use square brackets in this function, only for arrays with four numbers.
hexToRgb("172A60”)
5) in your variant colors will be changed instantly. We need to use linear or ease functions to make a smooth transition.
like this example
ease(r, 180, 300, hexToRgb("50E9FF"), hexToRgb("172A60"))
but for this one is better to use another condition range
r = thisComp.layer("Sun & Moon").transform.rotation; if (r > 180) {ease(r, 180, 300, hexToRgb("50E9FF"), hexToRgb("172A60"))} else {ease(r, 0, 180, hexToRgb("172A60"), hexToRgb("50E9FF"))}
————————— bonus
6) this option would work, but for one loop. Because layer rotation will go from 0 to infinity, when our condition checks only from 0 to 360. You need to set the animation range to 2 seconds. Another way to use the special Modulo operation (%) it helps to loop the value in the desired range
r = thisComp.layer("Sun & Moon").transform.rotation % 360