#92. Turning
When the green flag is clicked, this script runs. What is the cat's **direction**? (In Scratch, direction is between -179 and 180.)
when green flag clicked point in direction (90) turn right (150) degrees turn left (120) degrees
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
direction = fix_direction(direction + 150)
direction = fix_direction(direction - 120)
// 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;
direction = fixDirection(direction + 150);
direction = fixDirection(direction - 120);
💡 Not sure? Build it in Scratch and try it out.