πŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
πŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

Practical Exercise: Prompts

Test your skills in Prompt Engineering. Apply the 5-Layer framework, translate vague business requirements into Algorithmic Pseudocode, and practice strict Context Injection.

Narrated Video Summary
data-composition-id="aisoftwareengineering-exercise-prompt"1280Γ—720 @ 30fps6 clips2:32 total

Exercise 1: The Zero-Shot Trap

Welcome to the Practical Exercises. This section is designed to test your mastery of AI orchestration. First, we will test your prompt engineering. The single biggest mistake junior developers make is the 'Zero-Shot Trap'β€”asking the AI to build a massive system with a single sentence. You will now be presented with a vague prompt. Your goal is to identify why it fails and rewrite it using the 5-Layer Framework.

// ❌ The Vague Prompt:
"Build me a React login page."

// What happens?
The AI hallucinates an obsolete React 16 class component 
with no security, no CSS, and hardcoded passwords.

The 5-Layer Rewrite

To fix the vague prompt, you must inject Context. Remember the 5 Layers: Role, Context, Task, Constraints, Output Format. Your rewrite should look like this: 'Act as a Senior React Engineer. We are using Next.js 14 App Router, TailwindCSS, and NextAuth. Task: Build a responsive login component. Constraint: Do not use class components; use strictly functional components with hooks. Output: Return only the final code block.'

// βœ… The 5-Layer Prompt:
Role: Senior Frontend Engineer
Context: Next.js 14, Tailwind, NextAuth.
Task: Build a responsive Login Component.
Constraints: Use Server Actions. No Class Components.
Format: Only the raw code.

Exercise 2: Algorithmic English

Now let's practice writing 'Algorithmic English'. The prompt 'Write a function that calculates discounts' is terrible because it relies on the AI to guess the business rules. You must write the prompt like a compiler specification. Define the Exact Inputs, the Exact Processing Logic (Step 1, Step 2), and the Exact Outputs.

// ❌ Vague Business Logic:
"Make a function that applies a VIP discount to the cart."

// βœ… Algorithmic Pseudocode:
"Function: calculateVIP
Input: cart (Array), isVIP (boolean)
Logic:
 1. If isVIP is true, calculate 20% of total.
 2. If total > $100, add $10 flat discount.
Output: return finalPrice (number)."

The Context Window Test

The final prompt exercise tests Context Management. If you have a massive codebase and you ask 'Fix the bug where the user can't login', the AI will fail because it doesn't know where the login logic is. You MUST use the `@` feature to inject the specific files. The perfect prompt is: `@auth.ts @db-schema.prisma @api-routes.ts The user login fails. Find the bug in the auth logic based on the attached schema.`

// ❌ Missing Context:
"The JWT token is expiring too fast. Fix it."
// AI: "I cannot see your JWT configuration."

// βœ… Injected Context:
"@jwtConfig.ts @authMiddleware.ts
The token expires in 1 hour instead of 24. Fix the payload."

Exercise Complete

You have successfully passed the Prompt Engineering Practical Exercise. You understand the necessity of the 5-Layer Prompt, Algorithmic Pseudocode, and Context Injection. Next, we will apply these skills to a live Refactoring Exercise.

/* Prompting Mastered */
.exercises { next: 'exercise_refactoring'; }
0:00 / 2:32
Scene 1 / 6 β€” Exercise 1: The Zero-Shot Trap
⚑ Total XP: 0|πŸ’» aisoftwareengineering XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Exercise 1

Master Prompts.

Quick Quiz //

Why is the 'Zero-Shot Trap' (asking for a complex task in one sentence) dangerous in AI Software Engineering?


πŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
πŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

A tool is only as effective as the hands that wield it. To get Senior Engineer output from an AI, you must provide Senior Engineer inputs.

1The 5-Layer Drill

Never use a single-sentence prompt. Always define the Role ('Senior DB Admin'), the Context ('PostgreSQL 15'), the Task ('Optimize this query'), the Constraints ('Do not use materialized views'), and the Output Format ('Return only the SQL script'). If you omit constraints, the AI will default to the easiest, most generic solution, which is usually wrong for enterprise software.

βœ•
β€”
+
Layered Prompt:
Role: React Lead
Context: Next.js 14 Hooks
Task: Profile header form
Constraint: No Class components
localhost:3000
localhost:3000
Validated: Strict Next.js hook components output according to template definitions.

2The Algorithmic Drill

Do not ask the AI to guess business rules. If you need a payroll calculator, do not say 'calculate payroll'. Write out the exact steps: '1. Deduct 20% for tax if salary > 50k. 2. Add $500 bonus if hours > 160. 3. Return final payload as JSON.' This is called Algorithmic Pseudocode. You are acting as the compiler; the AI is merely translating your exact logic into syntax.

βœ•
β€”
+
VIP Discount prompt:
1. Check if user.isVIP is true.
2. If true, deduct 20%.
3. If cart total > 100, apply flat 10.
localhost:3000
localhost:3000
Logic check: Mathematical formulas mapped to functional conditional logic branches.

3The Context Drill

The AI is blind. It can only see what is in its immediate Context Window. If you ask it to fix a frontend component without attaching the backend API types, it will guess the types. Use your IDE's targeting features (like @types.ts or highlighting specific code blocks) to explicitly inject the necessary files. Think of the context window as a surgical tableβ€”only place the necessary tools on it.

βœ•
β€”
+
Laser Targeted Prompt:
@jwtConfig.ts @authMiddleware.ts
"Fix token expiry logic mismatch
based on configurations."
localhost:3000
localhost:3000
Surgically Resolved: Token signature key mapped to environment secrets module.

4Step-by-Step Breakdown

Exercise 1: The Zero-Shot Trap. Welcome to the Practical Exercises. This section is designed to test your mastery of AI orchestration. First, we will test your prompt engineering. The single biggest mistake junior developers make is the 'Zero-Shot Trap'β€”asking the AI to build a massive system with a single sentence. You will now be presented with a vague prompt. Your goal is to identify why it fails and rewrite it using the 5-Layer Framework.

The 5-Layer Rewrite. To fix the vague prompt, you must inject Context. Remember the 5 Layers: Role, Context, Task, Constraints, Output Format. Your rewrite should look like this: 'Act as a Senior React Engineer. We are using Next.js 14 App Router, TailwindCSS, and NextAuth. Task: Build a responsive login component. Constraint: Do not use class components; use strictly functional components with hooks. Output: Return only the final code block.'

Which part of the 5-Layer Prompt is critical for ensuring the AI doesn't hallucinate an obsolete, outdated version of your framework (e.g., using React Classes instead of Hooks)?

  • β†’The Role (e.g., 'Act as a Senior Engineer').
  • β†’The Context & Constraints (e.g., 'Context: React 18. Constraints: Use strictly functional components and Hooks. No classes.').

Exercise 2: Algorithmic English. Now let's practice writing 'Algorithmic English'. The prompt 'Write a function that calculates discounts' is terrible because it relies on the AI to guess the business rules. You must write the prompt like a compiler specification. Define the Exact Inputs, the Exact Processing Logic (Step 1, Step 2), and the Exact Outputs.

The Context Window Test. The final prompt exercise tests Context Management. If you have a massive codebase and you ask 'Fix the bug where the user can't login', the AI will fail because it doesn't know where the login logic is. You MUST use the @ feature to inject the specific files. The perfect prompt is: @auth.ts @db-schema.prisma @api-routes.ts The user login fails. Find the bug in the auth logic based on the attached schema.

If you ask an AI to fix a bug but you do not attach the relevant files (like @auth.ts), what will the AI do?

  • β†’It will magically read your hard drive and find the files itself.
  • β†’It will hallucinate a generic fix based on internet tutorials, which will likely break your specific app because it cannot see your actual code.

Exercise Complete. You have successfully passed the Prompt Engineering Practical Exercise. You understand the necessity of the 5-Layer Prompt, Algorithmic Pseudocode, and Context Injection. Next, we will apply these skills to a live Refactoring Exercise.

Build a Real Constrained Prompt. Finish building a prompt that includes an explicit output length constraint.

Level Up πŸš€

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1Semantic Usage

Using the proper structure for Exercise 1: The Zero-Shot Trap ensures that screen readers can correctly interpret the content hierarchy and purpose.

<!-- Apply semantic elements appropriately -->

SEO Implications

  • 1

    Contextual Relevance

    Proper implementation of Exercise 1: The Zero-Shot Trap provides search engine crawlers with better context, improving the indexing accuracy of your page.

Best Practices

Clean Code

Always validate your structure when using Exercise 1: The Zero-Shot Trap to prevent layout shifts and DOM inconsistencies.

Separation of Concerns

Keep styling and behavior separate from the structural markup of Exercise 1: The Zero-Shot Trap.

Frequent Bugs

THE BUG

Unexpected layout shifts or styling failures.

THE FIX

Ensure all implementations related to Exercise 1: The Zero-Shot Trap are properly structured according to strict specifications.

Real-World Examples

Production Usage

Here is how Exercise 1: The Zero-Shot Trap is typically implemented in a professional, robust application.

<!-- Best practice implementation of Exercise 1: The Zero-Shot Trap -->
<div class="production-ready">
  <!-- Content -->
</div>

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Not reading error messages carefully

Uncaught TypeError: Cannot read properties of undefined (reading 'length') // Solution: Ensure the variable you are calling .length on is initialized as a string or an array, not undefined.

The Solution //

Most of the time, the compiler or interpreter tells you exactly what line caused the crash and why. Read stack traces from the top down to identify the root cause.

The Error //

Hardcoding sensitive credentials

// Wrong const API_KEY = 'sk-123456789'; // Correct const API_KEY = process.env.API_KEY;

The Solution //

Never hardcode API keys, passwords, or secrets in your source code. Use environment variables (.env files) to keep them secure and out of version control.

Lesson Glossary

[01]Zero-Shot Trap

The mistake of asking an AI to perform a complex task with a single, vague sentence and zero context.

Code Preview
The Amateur Mistake

[02]5-Layer Framework

The rigorous prompting structure: Role, Context, Task, Constraints, Output Format.

Code Preview
The Structure

[03]Algorithmic Pseudocode

Writing out step-by-step logic in plain English, forcing the AI to strictly adhere to your business rules.

Code Preview
The Blueprint

[04]Context Injection

Explicitly attaching specific files, schemas, or type definitions to the prompt so the AI doesn't hallucinate missing data.

Code Preview
The Surgical Table

[05]Vague Requirement

A prompt that asks for an outcome but fails to define the parameters, leading to unpredictable AI generation.

Code Preview
The Enemy

Continue Learning