Category: Turtle
Gets the current y coordinate in pixels of the turtle.
The y coordinate is the distance from the turtle to the top of the screen.
var yLocation = getY(); console.log(yLocation); moveTo(100, 100); console.log(getY());
Top and to the Left Move a bit closer to the top left.
// Move a bit closer to the top left. var newX = getX() * 0.75; var newY = getY() * 0.75; moveTo(newX, newY);
Bounce the Turtle Have the turtle keep moving, but bounce off the walls so it stays on the screen.
// Have the turtle keep moving, but bounce off the walls so it stays on the screen. var speedX = 10; var speedY = 10; while (true) { var newX = getX() + speedX; var newY = getY() + speedY; if (newX < 20) { newX = 20; speedX = - speedX; } else if (newX > 300) { newX = 300; speedX = - speedX; } if (newY < 20) { newY = 20; speedY = - speedY; } else if (newY > 460) { newY = 460; speedY = - speedY; } moveTo(newX, newY); }
getY();
getY() does not take any parameters.
Returns a number representing the current y coordinate in pixels of the turtle within the app display.
Found a bug in the documentation? Let us know at documentation@code.org
Found a bug in the documentation? Let us know at documentation@code.org