Lesson 4.3 Variables Investigate
Sept 15 (A day) and Sept 16 (B day)
Sept 15 (A day) and Sept 16 (B day)
Check for Understanding
Code.org Assignment
Walk through Code.org U4L3 bubbles 1-7
Video
Complete bubbles 8-10
Wrap-Up - Make sure you have the vocabulary in your AJ. Then complete the Check for Understanding questions in Code.org
NaN - Not a Number
Scope - The area where you want a variable to act or be used.
Global variable - Permanent. Can be used anywhere in your code
Local variable - Temporary. Can be used only in the part of the code where it was created, like an onEvent().
Declaring a variable
Usually declared at the beginning of the program so it is easy to find.
Identifies a variable name that will be used somewhere in the program.
It may or may not assign an initial value
EXAMPLE: var time; Declares there is a variable called time
var time = 1:30 +"seconds"; Declares the variable called time and assigns a beginning value
When you create variables
Use var only once for any type of variable you will be declaring. (Once declared, it is always available to use.)
Create your variables at the top of your program. (This keeps your code organized.)
Create your variables OUTSIDE any onEvent blocks
In this lesson students spend most of their time practicing using the skills and processes they have learned about variables. At the conclusion of the lesson students discuss the main things they realized and still have questions about at the conclusion of this lesson.
This lesson is students primary opportunity to get hands on with variables in code prior to the Make activity in the following lesson. Give students as much class time as you can to work through these. For this lesson it's recommended that you place students in pairs as a support and to encourage discussion about the challenges or concepts they're seeing. In the following lesson students are encouraged to work independently.
CSP Conceptual Framework
AAP-1 - To find specific solutions to generalizable problems, programmers represent and organize data in multiple ways.
AAP-2 - The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.
AAP-3 - Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing programmers to write programs more quickly and with more confidence.
DAT-1 - The way that the computer represents data is different from the way that the data are interpreted and displayed for the user. Programs are used to translate data into a representation that is more easily understood by people.
CSTA K-12 Computer Science Standards (2017)
AP - Algorithms & Programming
2-AP-11 - Create clearly named variables that represent different data types and perform operations on their values.