Main content
Resources
Course: Resources > Unit 1
Lesson 3: Computer programming teachers- 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
© 2023 Khan AcademyTerms of usePrivacy PolicyCookie Notice
Teaching guide: Intro to JS - Variables
This is a teaching guide for the Intro to JS lesson on Variables.
What the student will learn
- How to define variables to store numeric values in their program.
- How to reassign variables to new values later.
- How to pass variables as parameters to their functions.
- How to include variables in math expressions.
- The rules for making up good variable names.
The student will be able to write code like:
Where students struggle
- Students sometimes ask what the point of variables is - why it’s worth it to go through the effort to learn the new concept. The very next lesson will show that you need variables to make animations, which are one really fun use of variables. Generally, variables enable you to make programs that are more complex than a drawing and can even make drawings easier to program, because the variables can store repeatedly used information. Plus, naming your variables allows you to communicate what the different numbers are used for in your program, making it easier for other people to understand and modify it (including yourself in the future!).
- Students might accidentally declare their variable after they use it. They’ll get an error if they do that, which should help remind them that variables must be defined first, and then used.
- Students sometimes give their variables invalid names, like a name with a space in it or a disallowed character. Remind them to re-read the variable naming rules in the review article.
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.
- Ask them about a favorite game and open it up. Prompt them to brainstorm what variables they think the game uses - what data the game has to store. For example, many games have a variable to store the player’s score, or a variable to store the current level.
- Ask them to look at their first project, the one they programmed before they knew about variables. Is there anything they'd use variables for now? For example, for the dinner plate project, a student might program multiple grapes, and they could now use a variable to store the grape size.
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.
Additional materials: Unplugged activities
An "unplugged" activity is one that you can do with students without needing to use a computer at all. They can help convey concepts in a more visceral way, and they can also be a backup activity for when computers fail.
Code.org offers a Variables in Envelopes activity (see lesson plan and video). It doesn’t align perfectly with this lesson because the variables in it often hold string data types, not numbers. We teach students how to store strings later. However, the concept of storing data is the same.
Want to join the conversation?
- jhdghd hthe thrbh hfhrt tghtteh thgw the th with re fbb rhg fg bhfvhva fhf jkdfsjflfirfkljfirkjfdfjhsf fjrhjfhfshuno(2 votes)