Main content
Course: Getting Started Teacher Training (U.S.) > Unit 6
Lesson 1: Teaching Computer Programming in the classroom- Programming content overview
- Tracking progress of programming students
- Classroom debugging guide
- Pair programming in the classroom
- Teaching guide: Intro to JS - Drawing Basics
- Teaching guide: Intro to JS - Coloring
- Teaching guide: Intro to JS - Variables
- Teaching guide: Intro to JS - Animation basics
- Teaching guide: Intro to JS - Interactive Programs
- Teaching guide: Intro to JS - Resizing with variable expressions
- Teaching guide: Intro to JS - Text and strings
- Teaching guide: Intro to JS - Functions
- Teaching guide: Intro to JS - Logic and if statements
- Teaching guide: Intro to JS - Looping
- Teaching guide: Intro to JS - Arrays
- Teaching guide: Intro to JS - Objects
- Teaching guide: Intro to JS - Object-oriented design
- Programming classroom handouts
- Additional programming projects
- Lesson plans: teaching programming in the classroom
- Programming case study: Encouraging cross-disciplinary projects
- Programming case study: Going beyond the KA curriculum
- Programming case study: Teaching an elementary school class
© 2024 Khan AcademyTerms of usePrivacy PolicyCookie Notice
Teaching guide: Intro to JS - Interactive Programs
This is a teaching guide for the Intro to JS lesson on Interactive programs.
What the student will learn
- How to use
mouseX
andmouseY
to make a program that draws shapes according to the current mouse position, like a painting app.
The student will be able to write code like:
Where students struggle
- Students may try to use
mouseX
andmouseY
outside of thedraw
function, and be disappointed their program doesn’t work. If they’re used outside thedraw
function, they’ll only hold the initial value of the mouse location. Those variables must be used inside thedraw
function, so that the program sees their values changing over time and updates accordingly. - Students may have trouble grasping how to use
mouseX
andmouseY
to change the color of their shapes. Remind them that RGB colors go from 0-255, andmouseX
andmouseY
will vary from 0-400. Encourage them to experiment with using the variables as different parameters to their functions, and seeing what happens as a result. Show them that they can also use the fourth parameter offill()
to change the opacity, for more cool effects.
Additional materials: Discussion questions
These are questions that you can ask students individually after they've done the lesson, or lead a group discussion around, if everyone's gotten to the same point.
- If you have arts and crafts supplies around, do some drawing or painting, and ask students how they would make a program that mimics the in-person art creation.
Additional materials: Trivia questions
These can be fun to do as a class after everyone’s gotten through the lesson. They can also lead to discussion about which questions are the hardest. Play them on Quizizz.
Want to join the conversation?
- var positions = [
{x: 100, y: 70, label: "Hope"},
{x: 100, y: 170, label: "Peace"},
{x: 100, y: 270, label: "Love"}
];
for (var i = 0; i < positions.length; i++) {
var position = positions[i];
fill(214, 32, 214);
ellipse(position.x, position.y, 100, 100);
fill(255, 255, 255);
text(position.label, position.x-15, position.y);
}(2 votes) - "Those variables must be used inside the draw function, so that the program sees their values changing over time and updates accordingly."
mouseX and mouseY can be used ANYWHERE in the program to get the current location of the mouse. The draw function should ONLY be used when the program is doing animation. Normal input should be from the mouse and keyboard functions.
(mouseMoved, mousePressed, mouseClicked... keyPressed, keyReleased ... etc)(1 vote)