Since the UI elements in your app are not static but can be moved, your app may need to know where a UI element currently is placed on the screen. All UI elements (button(), textInput(), textLabel(), dropdown(), checkbox(), radioButton(), image()), can be queried for their current position.
// add the Code.org logo at a random position on the screen and display it's position.
image("logo", "http://code.org/images/logo.png");
setPosition("logo", randomNumber(0,320), randomNumber(0,450));
write(getYPosition("logo"));
Check whether the logo has been displayed too close to the bottom edge.
// Check whether the logo has been displayed too close to the bottom edge.
image("logo", "http://code.org/images/logo.png");
setPosition("logo", randomNumber(0,320), randomNumber(0,450));
if (isCloseToEdge()){
write("Too Close to Edge");
}
function isCloseToEdge(){
if (getYPosition("logo")>=400) {
return true;
} else{
return false;
}
}
getYPosition(id);
| Name | Type | Required? | Description |
|---|---|---|---|
| id | string | The ID of the UI element to find the x position. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _. |
Returns a number representing the current y coordinate in pixels of the UI element within the app display.

Found a bug in the documentation? Let us know at documentation@code.org