> For the complete documentation index, see [llms.txt](https://docs.thunkable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.thunkable.com/~/revisions/A81b2aVlSXGVVaRtdFDr/functions.md).

# Functions

## Function Overview

A function is a block of code that performs a specific task. If you use the same code set multiple times in your project, you can work more efficiently using functions. Clear function names also make your code more readable.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2FFzTq7nyIeEX2rYVeaGne%2FnofunctionsH.png?alt=media\&token=a98e0408-3a56-4d58-a685-25c82616cd8c)

## Video Tutorial

You can view a video tutorial on using functions here:

{% embed url="<https://www.youtube.com/watch?v=3jS3F3IRQB0>" %}

## Create a function

You can use the following block to create a function and give it a name:

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2Fue6wlCzxR130XW67jZI5%2Fdosomething.png?alt=media\&token=b2e07513-eede-409d-94f7-2f021b71a806)

One example of a function is below. This function will create and shuffle a list of items.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2FOegMdluGVpuS9DvmmsA2%2Fshuffle.png?alt=media\&token=5797c869-a0aa-4873-a08e-2146974ffb53)

After you have created your function, you can simply use it at any time using the function block you have named:

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2FFAWasGYf51v0KgB979Fo%2Fcallshuffle.png?alt=media\&token=d533c7ea-590a-4b3c-9023-b9a80471a623)

## Create a function with an output

You can also create a function that returns a specific output.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MBmyLkaLb0XFn8rjwoA%2F-MBnDFgRiSp4Hg9osvFn%2Fdoandreturn.png?alt=media\&token=38280a10-4084-4f09-a6db-5d7bd3b958ea)

### Conditional Outputs

You can add multiple `return` blocks to your function. This allows you to return a different output based on some conditions.

For example, this function will take a rating out of 100, and return a description of the quality of the item being reviewed:

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MBmyLkaLb0XFn8rjwoA%2F-MBnEGfugDVrF6z8coeU%2Fqualfunc.png?alt=media\&token=482b86ca-78c9-4a64-b25e-c9c619e7d6f1)

The function will break when the `return` block is fired. For example, in the above example, if the quality rating is 100, the function will return **Perfect** and then stop. It will not run the other tests, and won't return **Excellent**. **Good**, **Fine**, etc.

## Inputs and Functions

You can click the gear icon to add inputs to your functions.&#x20;

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2F95kR5oVLLJXC8gUU3QpS%2Fdosomething2.png?alt=media\&token=66f51e29-343c-497c-9ee1-754553af879a)

You can then treat that input as a local variable in your function.

In this example, the function `change font size` takes a number as an input and sets the text on a Screen to this font size. The number can be fed in as the number selected on a [Slider](/~/revisions/A81b2aVlSXGVVaRtdFDr/slider.md), or the user can click a Reset [Button](/~/revisions/A81b2aVlSXGVVaRtdFDr/button.md) to set the font size back to 18.

![](https://1223006790-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LAn5scXl2uqUJUOqkJo-84897653%2Fuploads%2FqUvaCZe6FlwacjCc3rAb%2Fchange%20font%20size.png?alt=media\&token=eadf8115-7fa7-4840-ad1f-1de538fca1b9)
