Lesson Plan

Lesson Plan
Grade: Date: 17/01/2026
Subject: Information Technology IT
Lesson Topic: Use JavaScript timing events (setTimeout, setInterval)
Learning Objective/s:
  • Describe how the JavaScript event loop processes timer callbacks.
  • Differentiate between setTimeout and setInterval and select the appropriate one for a given task.
  • Write and debug code using setTimeout and setInterval, including clearing timers.
  • Apply best‑practice techniques to avoid drift, memory leaks, and scope issues.
  • Implement a simple debounce function using setTimeout.
Materials Needed:
  • Projector or interactive whiteboard
  • Computer lab with internet access
  • Code editor/IDE (e.g., VS Code) for each student
  • Sample HTML/JS starter files
  • Handout summarising timer syntax and best practices
  • Browser developer tools for debugging
Introduction:
Begin with a quick demo of a digital clock that updates every second, asking students what makes it tick. Recall prior learning about functions and the event loop, linking it to timed callbacks. Explain that by the end of the lesson they will be able to create, control, and troubleshoot JavaScript timers.
Lesson Structure:
  1. Do‑now (5') – Short quiz on the event loop and asynchronous code.
  2. Mini‑lecture (10') – Explain setTimeout, setInterval, and the task queue, using the clock demo.
  3. Guided coding (15') – Students write a setTimeout alert and a setInterval clock, then practice clearing timers.
  4. Pair activity (10') – Implement a background‑colour changer that stops after 30 seconds; peer review.
  5. Common pitfalls discussion (5') – Identify drift, minimum delay, memory leaks; rewrite a flawed setInterval example.
  6. Formative check (5') – Exit ticket: write one line of code to debounce a keyup handler.
Conclusion:
Summarise that setTimeout handles one‑off delays while setInterval provides repeated actions, emphasizing the need to clear timers. Students complete an exit ticket describing when to prefer recursive setTimeout over setInterval. For homework, ask them to create a simple slideshow using setInterval with proper cleanup.