Title: Scratch Programming
1Scratch Programming
- Lesson 5Programming logic
2We are going to learn
- Initialize the variables
- SET VS CHANGE
- Operator (Part II)
- Use a variable as a counter
3Initialization
- give an initial setting of a variable or set an
initial setting - use set functions
- for example,
4SET VS CHANGE
- See the following example
- What are the effect respectively?
The sprite will change its y co-ordinate by 10 whenever up arrow key is pressed The sprite will go to y10 whenever up arrow key is pressed
When the sprite is originally on y10 When the sprite is originally on y10
The sprite will move up by changing y co-ordinate The sprite will stay on y10
5Operators (Part II)
One number will be randomly chosen from the range
given
These three are operators (i.e. return True or
False)
AND OR NOT
True True False
False True True
False False False
6Operators (Part II)(cont.)
Mod Round
Reminder after division Round off the value with decimal places
Some more Maths function here
7Use variable as a counter
- Two methods have the same result
Adv easier to write Adv Can use the variable to set different cases at different values
Disadv cannot tell which repeat values is running Adv more difficult to write
8You can EXPLORE more by trying those functions
and right-click to find the help bubble
9Task of the lesson
- The sprite will give the user 3 chances to enter
a number from a range within the limit of 1 -15 - If the number guess is correct, suitable display
e.g. music and background will be shown - If the number guess is incorrect, suitable
display e.g. music and background will also be
shown - The number of guess left will be displayed
- The initialization of the a program has been
given. Complete the rest of the program.