Category: Turtle
Gets the current x coordinate in pixels of the turtle.
The x coordinate is the distance from the turtle to the left of the screen.
var xLocation = getX(); console.log(xLocation); moveTo(100, 100); console.log(getX());
To the Right Move the turtle 50 pixels to the right.
// Move the turtle 50 pixels to the right. var newX = getX() + 50; moveTo(newX, 100);
Am I off the screen? Check whether the turtle has moved off the right side of the screen.
// Check whether the turtle has moved off the right side of the screen. function isOffRight(){ if (getX() > 320) { return true } else{ return false } } turnRight(90); for(var i=0; i<10; i++){ moveForward(50); console.log("Am I off the screen? "+ isOffRight()); }
getX();
getX() does not take any parameters.
Returns a number representing the current x 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