Category: Turtle
Returns the current direction that the turtle is facing. Zero degrees is pointing up and the direction increases clockwise.
Sometimes the user controls the turtle and your app might need to know what direction the turtle is facing. The direction is a number between 0 and 359 degrees.
turnRight(randomNumber(359)); console.log(getDirection());
Turning on your Command Turn the turtle in a random direction, and display the direction, on every user click of a button.
// Turn the turtle in a random direction, and display the direction, on every user click of a button. textLabel("direction", "direction: " + getDirection()); button("random-direction", "Random Direction"); onEvent("random-direction", "click", function() { turnRight(randomNumber(359)); setText("direction", "direction: " + getDirection()); });
getDirection()
getDirection() does not take any parameters.
Returns an integer between 0 and 359 representing the direction the turtle is facing. [/returns]
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