Monday, September 22, 2014

9/24/14 - Snap! Variables

  When writing a program, we often need to store the value of some important concept used in our program, such as the value resulting from an intermediate computation. A variable is a concept in programming languages that allows us to associate a value with a symbolic name that can be used at different places in our program. There are specific rules for naming a variable, as mentioned on slide 2. It is important to assign the name of a variable as something that the variable represents. We often name our variables starting with a lower case letter. Sometimes, the best name may be more than one word, as in currentTaxYear or birthDate. In such cases, it is a convention to use what is called Camel Case, where the additional word is capitalized. These are just suggested conventions and not really the rules of Snap!




Try solving the exercise on slide 4 ("Variables" video) on your own, without looking at the answer on the later slides. The presentation offers two solutions to the "swap" concept. Do you understand these?

The last slide of the "Variables" video introduces the concept of a data type. It is helpful at times to know what values a particular variable can represent, such as numbers, strings, or other types of values. We will talk more about data types in a future lesson in this unit as it relates to creating our own blocks and being able to pass in values to those blocks.

The video below that will show you how to create variables in Snap!, including a solution to the swap exercise presented on slide 4.

No comments:

Post a Comment