> For the complete documentation index, see [llms.txt](https://ai-native-development.gitbook.io/archived/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-native-development.gitbook.io/archived/basic/comment-to-code.md).

# Generating Code from Comments

GitHub Copilot can also generate new code based on conditions specified by developers. For example, you can generate code by specifying the following conditions:

You can specify the following conditions to generate a new function:

```txt
// Function name: calculateAverage
// Function argument: numbers (array)
// Function return type: number
```

By specifying these conditions, GitHub Copilot generates the following code:

```ts
function calculateAverage(numbers: number[]): number {
    // Calculate the average of the array
    const sum = numbers.reduce((a, b) => a + b);
    return sum / numbers.length;
}
```

You can provide more complex definitions as well.
