-
Introduction
-
Introducing Scratch
- Scratch Ideas
-
Activities Overview
- Scratch Activities Project
-
Algorithms and Programs
-
Write an Algorithm
-
- Sequences
- Loops
- Data: Variables
- User Input
- Conditionals
- Conclusion
Adding a Question to Our Program
Adding a Question to Our Program
Now, we are going to make the Cat ask the user how many times he would like the Cat to dance.
The Cat will need to ask this question before the repeat block.
The stack of blocks below include the ask and wait block.
To make your stack of blocks match the above image, make sure that you:
- Drag an ask and wait block from the Sensing section of the Scripts tab and place it after the set number of movements to 0 block.
- Replace the text in the ask and wait block with: How many times would you like me to dance?
There is a special block in Scratch called answer, which you can find in the Sensing section of the Scripts tab.
When we use an ask and wait block, the answer variable will be set to the value given by the user to this question.
For example, read the stack of blocks below:
Say that you click the stack of blocks above and the Cat asks: What day of the week is it? If you then typed in the name of a day, for example: Monday, the Cat would then say: Yes! It is Monday
Now, we will use the answer given to the cat (the user input) to control how many times the Cat will repeat its dance.
To do this, drag the answer block from the Sensing section and replace the 2 in the first repeat block with the answer block, as shown below:
Press the space bar, answer the Cat's question and watch the Cat dance.
Does the Cat move the number of steps you expect?
After the Cat has finished its dancing, the value of the number of movements should be: the answer multiplied by 4.
Views | |
---|---|
1 | Total Views |
1 | Members Views |
0 | Public Views |
Share by mail
Please login to share this webpage by email.