ExpressionAssignsDRAFTNot Observed
Using a ()
variable in an operator block, such as in (score + 1)
also updates the value of the variable (score
in this case)
at the end of the evaluation.
An expression that reads a variable also updates its value after the evaluation
A variable is only written using an assignment
CorrectionHere is what's right.
Students might mistakenly believe that using a variable block
inside an operator block
also updates the value of the variable (score
in this case).
For example, they might believe that the following code causes the sprite to say 4, then 14, and then 14 again:
This is wrong. The above code makes the sprite say 4, 14, and 4.
To mutate a variable, one needs to use the set () to ()
block
or the change () by ()
block
OriginWhere could this misconception come from?
ValueHow can you build on this misconception?
This is an opportunity to discuss the concept of expressions.
In Scratch, we can compose expressions from numbers and strings and operator blocks.
We can directly type numbers or strings into holes. Numbers and strings are what is known as literals in other programming languages. They are the simplest kind of expressions.
We can also plug operator blocks into holes. There are two kinds of operator blocks: reporter blocks (that produce numbers or strings) and boolean blocks (that produce truth values). Operator blocks are known as operators in other languages. Here is an example of an operator block:
We can create an expression by filling in the holes of the operator block.
We can compose arbitrarily complex expressions in this way:
Any expression, when executed, produces a value. We say it gets “evaluated”.