#281. Turning in a loop
When the green flag is clicked, this script runs. What is the cat's **direction**? (-179..180)
when green flag clicked point in direction (90) repeat (2) turn right (30) degrees end
def fix_direction(d):
# In Scratch, direction stays between -179 and 180
d = (d + 180) % 360 - 180
return 180 if d == -180 else d
# The sprite's (cat's) position, direction and size
direction = 90
# When the green flag is clicked
direction = 90
for _ in range(2):
direction = fix_direction(direction + 30)
// In Scratch, direction stays between -179 and 180
function fixDirection(d) {
d = (((d + 180) % 360) + 360) % 360 - 180;
return d === -180 ? 180 : d;
}
// The sprite's (cat's) position, direction and size
let direction = 90;
// When the green flag is clicked
direction = 90;
for (let i = 0; i < 2; i++) {
direction = fixDirection(direction + 30);
}
💡 Not sure? Build it in Scratch and try it out.