Lesson 2: Working with an AI Assistant
Learning Objectives
- Choose an AI assistant and use it safely.
- Explain how a conversation with an AI assistant works, including what it remembers and what it forgets.
- Apply the PARSE workflow: plan, ask, read, scrutinize and edit.
- Write a learner profile and explain what each part of it does.
- Ask follow-up questions that help you understand the code an assistant writes.
2.1 Choosing an AI Assistant
Any of the popular AI assistants will work with this book: ChatGPT, Gemini, Claude or Microsoft Copilot, among others. The free version of any of them is enough. You'll need to sign in with an account, and it's worth using the same assistant throughout the book so its behavior becomes familiar.
Don't paste private information into an AI assistant. That includes passwords, access keys, and real data about other people, such as a list of names and email addresses from a club or class. The examples in this book use made-up data, so you can share them freely.
2.2 How a Conversation Works
A conversation with an AI assistant is a series of turns. You write a prompt, and the assistant writes a reply. Then you can write another prompt, and so on.
Prompt — The message you send to an AI assistant: a question, a request, or a description of what you want.
Three things about conversations matter for this book:
- The assistant remembers the conversation you're in. A follow-up like "Try again, but shorter" works because the assistant can see everything said so far in that chat.
- A new chat starts from nothing. Open a new conversation and the assistant knows nothing about your earlier ones. That's why you'll start every new chat with your learner profile, which you'll write later in this lesson.
- Replies vary. Send the same prompt twice and you'll get two different replies. They'll usually be similar, but the wording, and sometimes the code, will differ. The replies in this book are real ones, captured from Claude on the date shown. Yours won't match word for word, and that's expected.
2.3 PARSE: Plan, Ask, Read, Scrutinize, Edit
Every example in this book follows the same five steps. Their first letters spell PARSE, which is also what a computer does to your code before it runs it: it reads it closely, piece by piece.
- Plan. Before you ask for anything, decide what you want. What information goes in? What should come out? How will you know the result is right? A clear plan makes a clear prompt, and a clear prompt leaves the assistant less to guess.
- Ask. Write a prompt that describes your plan. In a new chat, start with your learner profile.
- Read. Go through the reply line by line. For each line, you should be able to say what it does. If you can't, ask the assistant to explain it, or to rewrite the code using only what you know.
- Scrutinize. Run the code and examine the result closely against your plan. Did the right values appear in the right places? Did anything change that shouldn't have? When the code works with real data, such as a spreadsheet, try it on a practice copy first.
- Edit. If the result isn't what you planned, tell the assistant exactly what happened and what you expected, or edit the code yourself.
Reading is the skill this book is really about. While you read, ask yourself four questions:
- What does each line do?
- Does it use anything I haven't learned?
- Does it change or delete anything?
- Does it match my plan?
And one rule applies to every example: don't run code you can't explain. Code can overwrite data, send email and share files, and it does those things as fast and as reliably as everything else.
2.4 Why Your Assistant Needs to Know What You Know
Here's a simple request, sent to an assistant in a brand-new chat with no other information:
Write JavaScript that adds up the numbers from 1 to 10.sendSum Numbers from 1 to 10
Here are a few different ways to accomplish this in JavaScript:
Method 1: Using a for loop
let sum = 0; for (let i = 1; i <= 10; i++) { sum += i; } console.log(sum); // 55Method 2: Using Array and reduce()
const sum = Array.from({length: 10}, (_, i) => i + 1) .reduce((acc, num) => acc + num, 0); console.log(sum); // 55Method 3: Using the Gauss formula (most efficient)
const n = 10; const sum = (n * (n + 1)) / 2; console.log(sum); // 55Method 4: Using a while loop
let sum = 0; let i = 1; while (i <= 10) { sum += i; i++; } console.log(sum); // 55All of these methods will output 55, which is the sum of numbers from 1 to 10 (1+2+3+4+5+6+7+8+9+10 = 55).
The for loop (Method 1) is the most common and straightforward approach, while the Gauss formula (Method 3) is the most efficient since it calculates the sum in constant time without any iteration.
All four methods are correct, and all four print 55. But look at them from a beginner's point of view. They use let and const, += and i++, for and while, Array.from, => and .reduce. The assistant chose four approaches at once, and it had no way to know that none of them would make sense to you yet.
This is where the rule "don't run code you can't explain" leaves you stuck. The code is probably fine, but you have no way to check it. So the natural next step is to ask for an explanation, which you can do in the same chat:
When reading the next AI chat, don't worry about trying to understand the whole response. The whole point is that you probably won't understand it.
Explain what each line of Method 2 does.send[…]
Array.from({length: 10}, (_, i) => i + 1)This creates an array with 10 elements containing the numbers 1-10.
{length: 10}— This is an "array-like" object. It just tellsArray.from()how many elements to create (10 in this case). It doesn't need to be a real array.(_, i) => i + 1— This is a mapping function that runs for each element:
_(underscore) is a placeholder for the first argument (the current element's value), which we don't need, so we use_as a convention to indicate "ignore this."iis the index of each element, starting at 0.i + 1transforms each index into the actual number we want (since index 0 → 1, index 1 → 2, etc.)Result: This line produces the array
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
.reduce((acc, num) => acc + num, 0)This takes the array and "reduces" it down to a single value (the sum).
reduce()— An array method that iterates through each element and accumulates a result.(acc, num) => acc + num— The callback function that runs for each element:
acc(accumulator) — keeps track of the running total.num— the current array element being processed.acc + num— adds the current number to the running total.0— This is the initial value foracc. Without this,reduce()would use the first array element as the starting point instead of 0.How it processes the array
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
Step acc (before) num acc (after) 1 0 1 1 2 1 2 3 3 3 3 6 4 6 4 10 5 10 5 15 ... ... ... ... 10 45 10 55 […]
The explanation is accurate and carefully organized. It even includes a table that follows the running total step by step. It still doesn't help much, because it explains unfamiliar code using more unfamiliar words: array, object, mapping function, argument, index, method, callback, accumulator. Each of those is a real idea you'll learn, but you'd need several of them before this explanation made sense.
The problem isn't the assistant. It answered the question it was given. The problem is that it didn't know who was asking. An explanation, like code, only helps if it's pitched at your level, and the assistant can't know your level unless you tell it.
2.5 Your Learner Profile
A learner profile is a short message you send at the start of every new chat. It tells the assistant what you're doing, what you already know, and how you'd like code written. Here is your first one:
Each part has a job:
- The first paragraph says who you are and where your code runs. "An online editor that shows console.log output" describes the code editors in this book's pages. You'll use one later in this lesson. Without this, the assistant has to guess where you'll run the code, as it did when it offered three places to run the hello program in Lesson 1. Welcome to Programming.
- "Use only the concepts listed below" is the most important rule. It asks the assistant to stay within what you know, and to say so when a task needs something new, instead of quietly using it.
- "Don't use semicolons" matches the style of this book, so the assistant's code looks like the code you'll read here. (You'll learn why semicolons are optional in the next lesson.)
- "Keep the code short and simple, and explain what each line does" asks for explanations as part of every answer, pitched at a beginner.
- "What I know so far" is the part that grows. Each lesson that teaches something new shows an updated profile, and you'll use the newest one from then on.
To use the profile, paste it as the first message of every new chat, before your first question. Here's what happened when this profile was sent to a new chat:
I'm a beginner learning JavaScript from a textbook, and I'd like your help learning it. I'm running JavaScript in an online editor that shows console.log output. I don't know any programming concepts yet. When you write code for me: - Use only the concepts listed below under "What I know so far." If a task needs something I haven't learned, tell me what it is instead of using it. - Don't use semicolons at the ends of lines. - Keep the code short and simple, and explain what each line does in plain language. What I know so far: nothing yet.sendGreat, let's start from the very beginning!
Since your editor shows
console.logoutput, that's the perfect place to start.console.logis a command that tells the computer to display something on the screen so you can see it.Here's the simplest example:
console.log("Hello")What this does:
console.log(...)means "show me whatever is inside the parentheses""Hello"is some text (in programming, text like this is called a string, and it needs quote marks around it)- Together, this line prints the word Hello to your console
Try running that in your editor and see what happens.
Once you've tried it, let me know and I'll introduce the next small concept — I'll only teach you one or two new things at a time so it doesn't get overwhelming. Sound good?
The assistant has changed how it behaves. Its code has no semicolon, it explains each part of the line in plain words, and it promises to go one or two ideas at a time.
Because the assistant explained the line, you can say what it does: it displays the word Hello. That means it passes the test of "don't run code you can't explain," so go ahead and run it. Click the Run button (▶) on the editor below, and the output appears underneath.
console.log("Hello")
Try changing the word between the quote marks, then run it again. You'll learn more about console.log and the other parts of this line in the next lesson.
Now the same request as before, in the same chat:
Write JavaScript that adds up the numbers from 1 to 10.sendThis task normally uses a concept called a loop (a way to repeat an action automatically) and variables (a way to store and update values) — you haven't learned those yet, so I won't use them.
But since you already know
console.log, we can still solve this in a simple way by just adding the numbers directly:console.log(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10)What this does:
console.log(...)displays whatever is inside the parentheses1 + 2 + 3 + ... + 10uses the+symbol to add numbers together, just like in math- The result (55) gets printed to your console
This works fine for adding a small list of numbers you can type out by hand. Later, once you learn variables and loops, I'll show you a way to do this that works even for huge lists of numbers (like 1 to 1,000,000) without typing them all out.
Want to try running this one, and then move on to learning about variables next?
This time the reply is one line you can read. The assistant noticed that the usual answer needs two things you haven't learned, loops and variables, and it told you so instead of quietly using them. Then it found a way to do the job with what you have: console.log and the plus sign. That's the profile working as intended.
Look closely and you'll see the assistant bent one rule. Your profile says you know nothing yet, but it used +. It made a sensible call, because + works the way it does in math, and it explained it. Still, it's the kind of choice you should notice. An assistant follows your profile as a strong guideline, not a law, and reading the reply is how you catch the places it made a judgment call.
The reply also mentions loops and variables, which are exactly the topics of the next several lessons. When you've worked through them, come back to Method 1 in the first reply. You'll be able to read every line.
console.log(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10)
When the assistant ignores your profile. In a long chat, an assistant can drift back to its usual habits, such as adding semicolons or using features you haven't learned. Remind it ("Please follow my learner profile: use only what I know"), or start a new chat and paste the profile again.
2.6 Asking Good Follow-Up Questions
The first reply is rarely the last word. Most of the value of an AI assistant comes from follow-up questions. These are worth keeping handy:
| Ask this | When |
|---|---|
| "Explain line 3 in plain language." | One line doesn't make sense. |
| "Rewrite this using only what I know." | The code uses something you haven't learned. |
| "What does this error message mean? Explain it, but don't fix it yet." | Your code stopped with an error. Understanding the error teaches you more than getting a fixed version. |
| "What would happen if the list were empty?" | You want to check an unusual case before trusting the code. |
| "Why did you use this approach instead of a simpler one?" | The code seems more complicated than the task. |
| "Does this code change or delete anything?" | Before you run code that works with real data. |
Notice that none of these ask the assistant to take over. Each one helps you understand the code well enough to decide for yourself whether it's right.
2.7 When Your Replies Don't Match the Book
When you send one of this book's prompts to your own assistant, your reply will almost certainly differ from the book's. Here's how to handle the differences:
- Compare the code, not the wording. Two replies can be worded completely differently and contain the same code.
- If your code differs, read it anyway. Different code can be just as correct. The Read step works the same way on any reply.
- If your reply uses something you haven't learned, ask the assistant to rewrite it using only what you know. That's a good sign your assistant needs a reminder to use your profile.
- If your reply is completely different, check that you started the chat with your current learner profile.
2.8 Summary
Any mainstream AI assistant works for this book, as long as you follow your course's rules and keep private information out of your chats. An assistant remembers the chat you're in, forgets everything when you start a new one, and words its replies differently every time. Every example follows five steps, PARSE: plan, ask, read, scrutinize and edit, and the rule behind them is that you don't run code you can't explain. Without context, an assistant answers a beginner's question with code and explanations pitched at an expert. A learner profile fixes that by telling it where your code runs, what you know, and how to write for you. You'll paste it at the start of every new chat, and it will grow with every lesson.