Now that you have your tools set up, let's talk about what it means to code with an AI partner. In this lesson, you'll learn the core philosophy of AI-assisted development and practice the basic mechanics of working with Codex.
The Philosophy: You are the Director
It's tempting to think of an AI coding assistant as a magic box that writes perfect code for you. This is not the case. A better analogy is that of a film director and a very fast, very knowledgeable, but sometimes very literal actor.
- You are the Director: You hold the vision. You know what the scene is about, what the characters should feel, and what the final product should look like. You are in charge of the creative decisions.
- Codex is the Actor: Codex can deliver lines (write code) incredibly quickly. It has memorized almost every script ever written (it's been trained on a massive amount of code). But it needs your direction to know what to do and how to do it.
Your job in this program is to get good at directing. This means breaking down big ideas into smaller, specific instructions that your AI partner can execute.
The Core Loop: Prompt, Review, Refine
Working with Codex follows a simple, iterative loop:
1.Prompt: Give Codex a clear, specific instruction in natural language.
2.Review: Carefully read the code that Codex generates. Does it do what you asked? Is it correct? Do you understand it?
3.Refine: If the code isn't quite right, give Codex a follow-up instruction to fix or change it. Or, edit the code yourself!
Let's try it.
✅ Exercise 1: Your First Prompt
1.Create a new file in VS Code called hello.js.
2.Open the Codex panel.
3.In the Codex chat, type the following prompt:
"In the hello.js file, create a JavaScript function called greet that takes a name as an argument and returns a string that says 'Hello, [name]!'"
4.Review the code. Codex should generate the function for you and place it in the file. Read it. Does it look right?
5.Now, let's refine it. Type this follow-up prompt:
"Now, call the greet function with the name 'World' and print the result to the console."
6.Review again. Codex should add the console.log line. Now, open the VS Code terminal (Ctrl+ or Control+ + `) and run the file by typing:
Bash
node hello.js
You should see "Hello, World!" printed in your terminal. Congratulations, you just co-wrote your first piece of code with an AI!
Best Practices for Prompting
The quality of your output depends heavily on the quality of your input. Here are some tips for writing good prompts:
- Be Specific: Instead of "make a button," try "create a React button component using shadcn/ui that has a blue background and says 'Click Me'."
- Provide Context: Tell Codex which files to look at or which functions to use. "Using the getUser function from utils.js, fetch the user and display their name."
- Break Down Problems: If you have a big task, break it down into smaller steps and prompt Codex for each one. Don't ask it to build the entire app in one go.
✅ Exercise 2: Practice Prompting
1.Create a new file called calculator.js.
2.Using only prompts to Codex, create a simple calculator that has four functions: add, subtract, multiply, and divide. Each function should take two numbers as arguments and return the result.
3.After creating the functions, write prompts to test each one of them with console.log.
4.Run the file with node calculator.js to see the results.
This new way of working might feel strange at first. The goal of this week is to get comfortable with the prompt-review-refine loop. The more you practice, the more it will feel like a natural conversation with your coding partner.