Learn the phrases and patterns developers use when writing prompts for AI code generation tools — from generating new functions to requesting refactors and error handling.
0 / 26 completed
1 / 26
A developer writes: '___ a function that parses a CSV and returns an array of objects.' What pattern are they using?
'Generate a function that...' is a core prompt pattern for code generation. It tells the AI to create new code from scratch based on what you describe — the more specific the description, the better the output.
2 / 26
You prompt the AI: '___ this to use async/await instead of callbacks.' Which pattern are you applying?
'Refactor this to use...' is used when you want the AI to transform existing code to apply a different approach — async/await, a design pattern, or a different library — without changing the underlying behaviour.
3 / 26
After generating a database call, you prompt: '___ ___ handling so it catches connection timeouts.' What are you asking?
'Add error handling' is a prompt extension that tells the AI to augment existing code with defensive patterns — try/catch, retries, input validation — making it more robust in production.
4 / 26
A senior engineer says: 'Your prompt lacks ___. Add the framework name and a short code sample so the AI knows what you need.'
Context in a prompt means including relevant background: the language, framework, existing code patterns, or examples. More context helps the AI generate output that fits your actual codebase rather than a generic solution.
5 / 26
Which of the following is the most effective prompt for generating a validation function?
An effective prompt specifies the language, input type, expected output, and key constraints. The more precise the prompt, the less the AI has to guess — leading to code you can use with minimal editing.
6 / 26
Sarah: 'I'm getting a vague error message from the AI when I ask it to refactor this code. It keeps suggesting changes I don't understand. My prompt is just 'refactor this function.' What could I do to get more targeted results?', specifically regarding how the AI understands my intent. Consider this PR description:
```diff
--- a/my_code.js
+++ b/my_code.js
@@ -12,6 +12,8 @@
function calculateTotal(items) {
let total = 0;
for (let i = 0; i < items.length; i++) {
total += items[i].price;
+ }
+ return total;
}
```
Which of the following prompt modifications would likely improve the AI's response in this scenario?
The key here is that AIs often struggle with ambiguous instructions. Simply stating 'refactor' doesn't provide enough context for the AI to understand *how* you want it to change the code. Option 2 is too broad and might lead to unintended consequences. Option 3 directly addresses the problem by specifying a goal – readability or complexity reduction – which guides the AI's actions. Option 4, while good practice, doesn't immediately address the root cause of the vague response; it requires the AI to *explain* itself first, which is often a slower process.
7 / 26
Sarah is struggling to get helpful refactoring suggestions from the AI. Her current PR description focuses only on the function's purpose ('calculateTotal'). To guide the AI more effectively, what specific detail should she add to her prompt?
The correct answer is option 1. The AI's understanding of a prompt is heavily influenced by context and constraints. Simply stating the function's purpose ('calculateTotal') is insufficient; the AI needs to know *how* it should calculate the total and what format the output should be in. Specifying expected data types, potential edge cases (e.g., negative prices), or desired output formats provides crucial guidance for the AI to generate more relevant and accurate refactoring suggestions. Options A and B are too broad; simply adding error handling isn't sufficient without specifying *what* errors to handle. Option C is helpful but doesn't directly address the AI's need for context.
8 / 26
You're working with an API that returns JSON data. You want the AI to generate a function that handles potential errors in the response. Which of the following prompts would be most effective?
(a) 'Generate code to fetch data from this API.'
(b) 'Create a function to parse the JSON response and handle any HTTP status codes other than 200, including error messages.'
(c) 'Write a function that retrieves the data and displays it in the console.'
(d) 'Generate an asynchronous function to call this API endpoint'
Option B explicitly asks for error handling – specifically, dealing with non-200 HTTP status codes. This is crucial when working with external APIs and ensures robust code. Options A and C are too generic and don't address potential issues. Option D focuses on asynchronicity but doesn't mention error handling.
9 / 26
A colleague sends you this Slack message: 'The AI is generating code that uses `forEach` when a `map` would be more appropriate for transforming an array. How can I improve the prompt to guide it towards using `map`?'. Which of the following actions would be most helpful in prompting the AI effectively?
(a) 'Use `forEach`.'
(b) 'Generate code that transforms arrays.'
(c) 'Specify that you want a function that returns a new array with transformed values, using `map`.'
(d) 'Fix the original code.'
The key here is to provide specific instructions to the AI. Option C directly tells it *what* you want – a function that uses `map` to create a new array from the transformed values. This eliminates ambiguity and guides the AI towards the desired outcome. Options A and B are too vague, while D is off-topic.
10 / 26
Sarah: 'I'm getting a vague error message from the AI when I ask it to refactor this code. It keeps suggesting changes I don't understand. My prompt is just 'refactor this function.' What could I do to get more targeted results?', specifically regarding how the AI understands my intent. Consider this PR description:
```diff
--- a/my_code.js
+++ b/my_code.js
@@ -12,6 +12,8 @@
function calculateTotal(items) {
let total = 0;
for (let i = 0; i < items.length; i++) {
total += items[i].price;
+ }
+ return total;
}
```
Which of the following prompt modifications would likely improve the AI's response in this scenario?
The key here is that AIs often struggle with ambiguous instructions. Simply stating 'refactor' doesn't provide enough context for the AI to understand *how* you want it to change the code. Option 2 is too broad and might lead to unintended consequences. Option 3 directly addresses the problem by specifying a goal – readability or complexity reduction – which guides the AI's actions. Option 4, while good practice, doesn't immediately address the root cause of the vague response; it requires the AI to *explain* itself first, which is often a slower process.
11 / 26
Sarah is struggling to get helpful refactoring suggestions from the AI. Her current PR description focuses only on the function's purpose ('calculateTotal'). To guide the AI more effectively, what specific detail should she add to her prompt?
The correct answer is option 1. The AI's understanding of a prompt is heavily influenced by context and constraints. Simply stating the function's purpose ('calculateTotal') is insufficient; the AI needs to know *how* it should calculate the total and what format the output should be in. Specifying expected data types, potential edge cases (e.g., negative prices), or desired output formats provides crucial guidance for the AI to generate more relevant and accurate refactoring suggestions. Options A and B are too broad; simply adding error handling isn't sufficient without specifying *what* errors to handle. Option C is helpful but doesn't directly address the AI's need for context.
12 / 26
You're working with an API that returns JSON data. You want the AI to generate a function that handles potential errors in the response. Which of the following prompts would be most effective?
(a) 'Generate code to fetch data from this API.'
(b) 'Create a function to parse the JSON response and handle any HTTP status codes other than 200, including error messages.'
(c) 'Write a function that retrieves the data and displays it in the console.'
(d) 'Generate an asynchronous function to call this API endpoint'
Option B explicitly asks for error handling – specifically, dealing with non-200 HTTP status codes. This is crucial when working with external APIs and ensures robust code. Options A and C are too generic and don't address potential issues. Option D focuses on asynchronicity but doesn't mention error handling.
13 / 26
A colleague sends you this Slack message: 'The AI is generating code that uses `forEach` when a `map` would be more appropriate for transforming an array. How can I improve the prompt to guide it towards using `map`?'. Which of the following actions would be most helpful in prompting the AI effectively?
(a) 'Use `forEach`.'
(b) 'Generate code that transforms arrays.'
(c) 'Specify that you want a function that returns a new array with transformed values, using `map`.'
(d) 'Fix the original code.'
The key here is to provide specific instructions to the AI. Option C directly tells it *what* you want – a function that uses `map` to create a new array from the transformed values. This eliminates ambiguity and guides the AI towards the desired outcome. Options A and B are too vague, while D is off-topic.
14 / 26
Sarah: 'I'm getting a vague error message from the AI when I ask it to refactor this code. It keeps suggesting changes I don't understand. My prompt is just 'refactor this function.' What could I do to get more targeted results?', specifically regarding how the AI understands my intent. Consider this PR description:
```diff
--- a/my_code.js
+++ b/my_code.js
@@ -12,6 +12,8 @@
function calculateTotal(items) {
let total = 0;
for (let i = 0; i < items.length; i++) {
total += items[i].price;
+ }
+ return total;
}
```
Which of the following prompt modifications would likely improve the AI's response in this scenario?
The key here is that AIs often struggle with ambiguous instructions. Simply stating 'refactor' doesn't provide enough context for the AI to understand *how* you want it to change the code. Option 2 is too broad and might lead to unintended consequences. Option 3 directly addresses the problem by specifying a goal – readability or complexity reduction – which guides the AI's actions. Option 4, while good practice, doesn't immediately address the root cause of the vague response; it requires the AI to *explain* itself first, which is often a slower process.
15 / 26
Sarah is struggling to get helpful refactoring suggestions from the AI. Her current PR description focuses only on the function's purpose ('calculateTotal'). To guide the AI more effectively, what specific detail should she add to her prompt?
The correct answer is option 1. The AI's understanding of a prompt is heavily influenced by context and constraints. Simply stating the function's purpose ('calculateTotal') is insufficient; the AI needs to know *how* it should calculate the total and what format the output should be in. Specifying expected data types, potential edge cases (e.g., negative prices), or desired output formats provides crucial guidance for the AI to generate more relevant and accurate refactoring suggestions. Options A and B are too broad; simply adding error handling isn't sufficient without specifying *what* errors to handle. Option C is helpful but doesn't directly address the AI's need for context.
16 / 26
You're working with an API that returns JSON data. You want the AI to generate a function that handles potential errors in the response. Which of the following prompts would be most effective?
(a) 'Generate code to fetch data from this API.'
(b) 'Create a function to parse the JSON response and handle any HTTP status codes other than 200, including error messages.'
(c) 'Write a function that retrieves the data and displays it in the console.'
(d) 'Generate an asynchronous function to call this API endpoint'
Option B explicitly asks for error handling – specifically, dealing with non-200 HTTP status codes. This is crucial when working with external APIs and ensures robust code. Options A and C are too generic and don't address potential issues. Option D focuses on asynchronicity but doesn't mention error handling.
17 / 26
A colleague sends you this Slack message: 'The AI is generating code that uses `forEach` when a `map` would be more appropriate for transforming an array. How can I improve the prompt to guide it towards using `map`?'. Which of the following actions would be most helpful in prompting the AI effectively?
(a) 'Use `forEach`.'
(b) 'Generate code that transforms arrays.'
(c) 'Specify that you want a function that returns a new array with transformed values, using `map`.'
(d) 'Fix the original code.'
The key here is to provide specific instructions to the AI. Option C directly tells it *what* you want – a function that uses `map` to create a new array from the transformed values. This eliminates ambiguity and guides the AI towards the desired outcome. Options A and B are too vague, while D is off-topic.
18 / 26
Sarah: 'I'm getting a vague error message from the AI when I ask it to refactor this code. It keeps suggesting changes I don't understand. My prompt is just 'refactor this function.' What could I do to get more targeted results?', specifically regarding how the AI understands my intent. Consider this PR description:
```diff
--- a/my_code.js
+++ b/my_code.js
@@ -12,6 +12,8 @@
function calculateTotal(items) {
let total = 0;
for (let i = 0; i < items.length; i++) {
total += items[i].price;
+ }
+ return total;
}
```
Which of the following prompt modifications would likely improve the AI's response in this scenario?
The key here is that AIs often struggle with ambiguous instructions. Simply stating 'refactor' doesn't provide enough context for the AI to understand *how* you want it to change the code. Option 2 is too broad and might lead to unintended consequences. Option 3 directly addresses the problem by specifying a goal – readability or complexity reduction – which guides the AI's actions. Option 4, while good practice, doesn't immediately address the root cause of the vague response; it requires the AI to *explain* itself first, which is often a slower process.
19 / 26
Sarah is struggling to get helpful refactoring suggestions from the AI. Her current PR description focuses only on the function's purpose ('calculateTotal'). To guide the AI more effectively, what specific detail should she add to her prompt?
The correct answer is option 1. The AI's understanding of a prompt is heavily influenced by context and constraints. Simply stating the function's purpose ('calculateTotal') is insufficient; the AI needs to know *how* it should calculate the total and what format the output should be in. Specifying expected data types, potential edge cases (e.g., negative prices), or desired output formats provides crucial guidance for the AI to generate more relevant and accurate refactoring suggestions. Options A and B are too broad; simply adding error handling isn't sufficient without specifying *what* errors to handle. Option C is helpful but doesn't directly address the AI's need for context.
20 / 26
You're working with an API that returns JSON data. You want the AI to generate a function that handles potential errors in the response. Which of the following prompts would be most effective?
(a) 'Generate code to fetch data from this API.'
(b) 'Create a function to parse the JSON response and handle any HTTP status codes other than 200, including error messages.'
(c) 'Write a function that retrieves the data and displays it in the console.'
(d) 'Generate an asynchronous function to call this API endpoint'
Option B explicitly asks for error handling – specifically, dealing with non-200 HTTP status codes. This is crucial when working with external APIs and ensures robust code. Options A and C are too generic and don't address potential issues. Option D focuses on asynchronicity but doesn't mention error handling.
21 / 26
A colleague sends you this Slack message: 'The AI is generating code that uses `forEach` when a `map` would be more appropriate for transforming an array. How can I improve the prompt to guide it towards using `map`?'. Which of the following actions would be most helpful in prompting the AI effectively?
(a) 'Use `forEach`.'
(b) 'Generate code that transforms arrays.'
(c) 'Specify that you want a function that returns a new array with transformed values, using `map`.'
(d) 'Fix the original code.'
The key here is to provide specific instructions to the AI. Option C directly tells it *what* you want – a function that uses `map` to create a new array from the transformed values. This eliminates ambiguity and guides the AI towards the desired outcome. Options A and B are too vague, while D is off-topic.
22 / 26
During a code review, Liam comments on a PR draft: 'The AI's suggested changes to the authentication module seem overly verbose. Could you prompt it to prioritize conciseness and readability while maintaining security?' Which of the following prompts would best address Liam's feedback?
Liam is specifically pointing out verbosity. Option 1 is too broad. Option 2 directly addresses the need for conciseness and readability alongside security – mirroring Liam's concern. Options 3 and 4 focus on less relevant aspects (efficiency/simplicity) and don't acknowledge the core issue of overly verbose code.
23 / 26
You're receiving an API response in JSON format indicating a failed payment attempt. The AI needs to generate code that gracefully handles this error. Which of the following prompts is most effective for instructing the AI?
Option 2 is the most precise. It specifies focusing on HTTP 500 errors (a common indicator of API failures) from *this specific* payment API. Options 1 is too general; options 3 and 4 are overly broad, lacking detail about error codes or logging.
24 / 26
Maya sends this Slack message: 'The AI is consistently generating code that uses `filter` when `slice` would be more appropriate for extracting a portion of an array. I need to help it understand the difference.' What advice should you give Maya regarding prompt engineering?
Maya highlights a misunderstanding of array manipulation. The key is explaining that `slice` creates a *new* array without modifying the original, while `filter` *modifies* the original. Option 2 provides the core conceptual guidance needed.
25 / 26
David writes this PR description for an AI-generated function: 'This function processes user data.'. The AI is consistently producing unhelpful suggestions. What should David add to the PR description to improve the prompt?
David's original description is extremely vague. Option 1 provides crucial details about the input and output formats – essential for guiding the AI towards generating useful code. Options 2, 3, and 4 are still too high-level.
26 / 26
You're reviewing a PR generated by an AI tool. The code uses the term 'normalize' but doesn't actually perform any data cleaning or standardization. What specific instruction could you add to your prompt to ensure the AI correctly implements normalization?
The word 'normalize' has multiple meanings. Option 2 provides a comprehensive definition of normalization – encompassing data cleaning, handling inconsistencies, and type conversions. The other options address related but distinct concerns (regex validation, performance optimization, or naming conventions).
What will I practice in "Prompting AI Coding Tools — Vocabulary"?
This is an AI Code Generation Tools exercise set. It walks through 26 scenario-based multiple-choice questions built around real usage of AI Code Generation Tools terminology that IT professionals encounter on the job.
Is this exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is free to complete with no account, sign-up, or paywall.
How many questions are in this exercise?
This set contains 26 questions. Each one shows immediate feedback and a detailed explanation after you answer, so you learn the correct usage right away rather than waiting for a final score.
Do I need prior experience to complete this exercise?
No prior experience is required. Each question includes a full explanation covering the reasoning behind the correct answer, so the exercise itself teaches the AI Code Generation Tools vocabulary as you go.
Can I retry the exercise if I get questions wrong?
Yes — use the "Try again" button on the results screen to reset your answers and go through all the questions again. There is no limit on attempts.
Is my progress saved?
Your answers and score for the current session are tracked in the browser as you go. No account or login is needed, and there is nothing to install.
What if I don't understand a term used in a question?
Read the explanation shown after you answer each question — it breaks down the correct term in plain English with a real-world example. You can also check the site Glossary for quick definitions.
How is this different from reading a blog article on the topic?
Exercises like this one are interactive drills that test and reinforce specific vocabulary through multiple-choice questions, while blog articles explain concepts in prose. Practising here after reading builds active recall, not just passive recognition.
Where can I find more AI Code Generation Tools exercises?
See the AI Code Generation Tools exercises hub for the full set of related pages, or browse all exercise categories from the main Exercises index.
Can I use this exercise to prepare for a technical interview?
Yes — AI Code Generation Tools vocabulary comes up often in technical discussions and interviews. Pair this exercise with our dedicated Interview Preparation section for role-specific practice.