Master Modern Engineering
Hands-on coding challenges to sharpen your skills in real-time.
01. Prompt Engineering Technique: Few-Shot
In the editor below, you'll find a template. Your task is to craft a few-shot prompt that converts informal slang into professional business English. Provide at least 2 examples in the prompt.
01. Variables & Data Types
Declare a constant 'username' with your name and a let variable 'score' initialized to 0. Log both.
02. Conditionals & Logic
Create an 'age' variable. Write an if/else statement that logs 'Welcome' if age is 18 or older, and 'Access Denied' otherwise.
02. Crafting Effective Prompts: Context & Constraints
Create a prompt for an AI that acts as a Front-end UI/UX Critic. Ask it to review a landing page description. Constraints: Tone must be 'constructive but firm', and the output must be a bulleted list of exactly 3 points.
03. Functions & Scope
Write a function 'calculateTotal' that takes 'price' and 'quantity' as arguments and returns the total. Log the result for (25, 4).
03. Prompt Engineering Patterns: Chain-of-Thought
Craft a Chain-of-Thought prompt for a logical puzzle. The AI must first state the known facts, then the intermediate steps, and finally the conclusion.
04. Array Transformation
Given an array of numbers [2, 4, 6, 8], use .map() to create a new array where each number is squared. Log the result.
04. Integrating the GenAI SDK
We will use the official Google GenAI SDK to interact directly with an LLM from our browser sandbox. **Step 1.** Import `GoogleGenAI` from `https://esm.sh/@google/genai`. **Step 2.** Initialize the client: `const ai = new GoogleGenAI({ apiKey: 'YOUR_GEMINI_API_KEY' })`. **Step 3.** Use `ai.models.generateContent` with the model `gemini-2.5-flash` to ask: "Explain APIs to a 5-year-old in one sentence." **Step 4.** Log `response.text` to the console.
04. Projects for Practice: Building a Code Assistant
Write a complete System Prompt for an AI bot called 'Tailwind-GPT'. It should only answer questions about Tailwind CSS. If asked about other CSS frameworks, it must politely decline. It should provide code snippets for all answers.
05. Loops & Iteration
Write a 'for' loop that logs the numbers from 5 down to 1 (countdown).
05. Maintaining Conversation History
AI models are stateless; they don't remember previous messages unless you send the entire history every time. Let's use the SDK's built-in chat session manager. **Step 1.** Initialize `GoogleGenAI`. **Step 2.** Create a chat session using `ai.chats.create({ model: 'gemini-2.5-flash' })`. **Step 3.** Send a message: `"I have 5 apples."` and log the response text. **Step 4.** Send another message: `"I ate 2 of them. How many do I have left?"` and log the response.
06. Capstone: Simple Calculator
Create an object 'calculator' with a method 'operate' that takes (a, b, operation). Support 'add' and 'multiply'. Log the result of (10, 5, 'add').
06. Structured JSON Outputs
When building applications, you often need the AI to return parsable data (like JSON) instead of raw conversational text. **Step 1.** Ask the AI to generate details for a famous sci-fi movie (Title, Director, Year). **Step 2.** Pass the `config: { responseMimeType: 'application/json' }` option alongside the model and contents. **Step 3.** Log the result. Try doing `JSON.parse(response.text)` to prove it's valid data!
07. System Instructions & Persona
System instructions dictate the fundamental rules of behavior for the AI across an entire session. **Step 1.** Draft a system instruction that tells the AI it is a "Pirate Coding Assistant" who must speak entirely in pirate slang, but still provide accurate JavaScript answers. **Step 2.** Use `ai.models.generateContent` and pass your system instruction into the `config.systemInstruction` field. **Step 3.** Ask it: "How do I declare a variable in JavaScript?" and log the results.