Coding with AI: Prompts & Reading JavaScript

Learn how to write effective AI prompts and read JavaScript code confidently. This lesson teaches students how to direct AI instead of blindly copying its output.

~4 min read updated Jul 17, 2026 Teaching
  • #ai
  • #javascript
  • #prompt engineering
  • #beginners

This lesson introduces two essential skills for modern programmers:

  1. Writing effective prompts that guide AI toward the desired solution.
  2. Reading and understanding the JavaScript code that AI generates.

The objective is not to memorize JavaScript syntax, but to become confident enough to explain what AI-generated code is doing. oaicite:0

Learning Objectives

After completing this lesson, students should be able to:

  • Explain what a prompt is.
  • Write clearer prompts that produce better AI output.
  • Follow a structured AI workflow instead of randomly asking for code.
  • Recognize common JavaScript syntax.
  • Read and explain basic JavaScript programs.
  • Identify variables, functions, conditions, loops, arrays, and objects in code. oaicite:1

Presentation

Google Slides

Day 2 – Coding with AI: Prompts & Reading JavaScript

Lesson Outline

Why Prompting Matters

Review the previous activity where students asked AI to create a calculator.

Students compare two approaches:

  • A vague request that leaves every decision to the AI.
  • A detailed prompt that clearly describes the desired application.

The lesson emphasizes that better prompts produce better results because the AI cannot read your mind. oaicite:2

The Four Parts of a Good Prompt

Students learn a simple framework for writing prompts.

A good prompt includes:

  • Context – Who is the project for?
  • Goal – What should it do?
  • Requirements – Rules and must-have features.
  • Output – What format should the AI produce?

This structure gives AI enough information to generate more accurate results. oaicite:3

The Prompt Loop

Instead of asking AI for code immediately, students follow a repeatable workflow.

  1. Draft
  2. Improve
  3. Review
  4. Plan
  5. Review
  6. Execute

This process keeps the student in control while allowing AI to assist with implementation. oaicite:4

Why Learn JavaScript?

Students discuss an important classroom rule:

You may only submit code you can explain.

Rather than memorizing every syntax rule, students learn just enough JavaScript to understand the code generated by AI. oaicite:5

Variables

Introduce variables as labeled boxes for storing information.

Topics include:

  • let
  • const
  • Variable names
  • Numbers
  • Strings

Students learn how values are stored and referenced in JavaScript. oaicite:6

Values and Operators

Learn the basic JavaScript value types:

  • Number
  • String
  • Boolean

Students also learn common operators used for:

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Comparison

These operators form the foundation of program logic. oaicite:7

Decisions with if / else

Students learn how programs make decisions.

Topics include:

  • if
  • else
  • Conditions
  • Comparison operators
  • Curly braces

Students practice reading conditional logic in plain English. oaicite:8

Loops

Introduce loops as a way to repeat actions without copying code.

Students learn:

  • for...of
  • Repeating actions
  • Processing every item in a list

The emphasis is on eliminating duplicated code. oaicite:9

Functions

Students learn that functions are reusable mini-machines.

Topics include:

  • Parameters
  • Return values
  • Calling functions
  • Reusability

The lesson reinforces that AI-generated code frequently uses functions, making them an essential concept to recognize. oaicite:10

Arrays and Objects

Students learn the difference between:

  • Arrays (lists)
  • Objects (one item with details)

These structures appear constantly in modern JavaScript applications and AI-generated code. oaicite:11

Reading Real JavaScript

The lesson concludes by reading an actual JavaScript function.

Students identify:

  • Functions
  • Variables
  • Objects
  • Arrays
  • Conditions

The focus is on recognizing familiar building blocks rather than understanding every character of the program. oaicite:12

Hands-on Activities

Complete the following activities after finishing this lesson.

Exercise 1 – Read & Predict

Analyze a JavaScript function before running it.

Students practice:

  • Reading code
  • Predicting output
  • Identifying functions, variables, and conditions
  • Verifying their predictions

➡️ Activity: /teaching/activities/read-and-predict


Dynamic Portfolio Website

Build a portfolio website using JavaScript instead of hardcoded HTML.

Students practice:

  • Arrays of objects
  • Loops
  • DOM manipulation
  • Reusable functions
  • Dynamic content generation

➡️ Activity: /teaching/activities/dynamic-portfolio-website

Key Takeaways

The goal of this lesson is not to become dependent on AI.Instead, students should learn to direct AI effectively by writing clear prompts and verifying the generated code.Remember:
  • A good prompt steers the AI.
  • AI should provide a plan before code.
  • Review the AI's work before accepting it.
  • Only submit code that you can confidently explain.
These habits prepare students to use AI as a productive programming assistant rather than a copy-and-paste machine. oaicite:13

Related notes