Ai Coding Tools

How to Use GitHub Copilot to Write a Function in 10 Minutes

By BTW Team3 min read

How to Use GitHub Copilot to Write a Function in 10 Minutes

If you're a solo founder or indie hacker, you know that time is money. The faster you can get features out the door, the better. Enter GitHub Copilot, an AI-powered code completion tool that can help you write functions in record time. In this guide, I'm going to show you how to leverage GitHub Copilot to write a function in about 10 minutes.

Prerequisites

Before we dive in, make sure you have the following:

  • A GitHub account (Free or Pro)
  • Visual Studio Code (VS Code) installed
  • GitHub Copilot extension for VS Code (Free trial available, then $10/month)

Step 1: Install GitHub Copilot

First, you need to install the GitHub Copilot extension in VS Code. Here’s how:

  1. Open VS Code.
  2. Go to Extensions (or press Ctrl + Shift + X).
  3. Search for "GitHub Copilot" and click "Install."
  4. Sign in with your GitHub account.

Expected Output: You should see a small Copilot icon in the bottom-right corner of your VS Code.

Step 2: Create a New File

Create a new file in your desired programming language (e.g., JavaScript, Python). For this example, let’s create a simple addNumbers function in JavaScript.

  1. Click on File > New File.
  2. Save it as addNumbers.js.

Expected Output: A blank JavaScript file.

Step 3: Write a Comment for Your Function

Start by writing a comment that describes what you want the function to do. For example:

// This function adds two numbers and returns the sum.

Expected Output: Copilot should recognize the comment and suggest code.

Step 4: Accept the Suggestion

Once you write the comment, GitHub Copilot will automatically suggest a function implementation. It might look something like this:

function addNumbers(a, b) {
    return a + b;
}

Simply press Tab to accept the suggestion.

Expected Output: The addNumbers function is now written in your file.

Step 5: Test the Function

Now, let’s test the function by calling it and logging the result:

console.log(addNumbers(5, 10)); // Expected output: 15

Expected Output: You should see 15 in the console when you run the file.

Troubleshooting: What Could Go Wrong

  1. No Suggestions: If Copilot doesn’t suggest anything, make sure the extension is enabled and that you’re connected to the internet.
  2. Incorrect Code: Sometimes the suggestions may not be accurate. Always validate and test the code.

What's Next

Now that you know how to use GitHub Copilot to write a simple function, you can explore more complex functionalities. Try writing functions that handle arrays or objects. The more specific you are in your comments, the better the suggestions will be.

Conclusion: Start Here

In our experience, GitHub Copilot is a fantastic tool for accelerating coding tasks. It's particularly useful for solo founders who need to produce code quickly without getting bogged down in syntax. If you’re looking to save time while coding, I recommend giving it a shot.

Pricing Breakdown

| Feature | Pricing | Best For | Limitations | Our Take | |---------------------|-----------------------|---------------------------------|----------------------------------|-------------------------------| | GitHub Copilot | Free trial, then $10/mo | Quick function writing | May generate incorrect code | We use this for rapid prototyping |

What We Actually Use

We primarily use GitHub Copilot for generating boilerplate code and quick functions, especially when we're on tight deadlines. If you're looking for alternatives, tools like TabNine ($12/mo) or Codeium (Free) might be worth exploring, but Copilot has been the most reliable in our experience.

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

Why ChatGPT-3 for Coding is Overrated: A Deep Dive

Why ChatGPT3 for Coding is Overrated: A Deep Dive As a solo founder or indie hacker, the allure of using AI tools like ChatGPT3 for coding can be tempting. The idea of having an AI

Aug 20, 20264 min read
Ai Coding Tools

How to Generate Code with GitHub Copilot in Under 5 Minutes

How to Generate Code with GitHub Copilot in Under 5 Minutes If you’re a solo founder or side project builder, you know that time is of the essence. Learning a new technology can fe

Aug 20, 20263 min read
Ai Coding Tools

Cursor vs Codeium: Which AI Coding Assistant is Better for Pro Developers?

Cursor vs Codeium: Which AI Coding Assistant is Better for Pro Developers? As a professional developer, you know the struggle of balancing productivity with the quality of your cod

Aug 20, 20263 min read
Ai Coding Tools

10 AI Coding Mistakes to Avoid for Efficient Development

10 AI Coding Mistakes to Avoid for Efficient Development As a solo founder or indie hacker in 2026, the allure of AI coding tools is hard to resist. They promise to boost productiv

Aug 20, 20264 min read
Ai Coding Tools

How to Build Your First App with GPT-4 in Under 2 Hours

How to Build Your First App with GPT4 in Under 2 Hours Building your first app can feel overwhelming, especially if you’re a solo founder or indie hacker. You might think you need

Aug 20, 20264 min read
Ai Coding Tools

3 Mistakes New Developers Make with AI Coding Tools

3 Mistakes New Developers Make with AI Coding Tools As a new developer diving into the world of AI coding tools, it's easy to get overwhelmed by the myriad of options available. In

Aug 20, 20263 min read