madlib-input, strings, and lists in scratch barb ericson georgia tech june 2011
TRANSCRIPT
![Page 1: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/1.jpg)
Madlib-Input, Strings, and Madlib-Input, Strings, and Lists in ScratchLists in Scratch
Madlib-Input, Strings, and Madlib-Input, Strings, and Lists in ScratchLists in Scratch
Barb EricsonBarb EricsonGeorgia TechGeorgia Tech
June 2011June 2011
![Page 2: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/2.jpg)
Concepts• Strings are groups of characters
– You can join two strings together– You need to add spacing between strings
• Lists – store items in an order– You can add items to a list– You can get an item at a position in a list
![Page 3: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/3.jpg)
Project Description• We will ask the
user some questions and then create a "madlib" from the answers
![Page 4: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/4.jpg)
Big Picture• Delete the cat
sprite• Choose a sprite
from a file• Program the
sprite– Create a script
– Do set-up– Repeat 3 times
• Ask user a question
• Add answer to a list
– Create a string to say the result
![Page 5: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/5.jpg)
Delete cat sprite• To delete the cat
– Click the scissors– Click the cat
• Or right click on the cat and select delete
![Page 6: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/6.jpg)
Choose a Sprite• Select the choose
a sprite from a file
• Go to the People category
• Pick a sprite to use
![Page 7: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/7.jpg)
Program the Sprite• We want to ask
the user 3 questions– Name– Favorite color– Favorite Animal
• Use the "ask and wait" tile in the Sensing category
![Page 8: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/8.jpg)
Saving the answers• Each time we ask a
question the answer is put in the answer tile – in Sensing
• To save the answers let's add them to a list
![Page 9: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/9.jpg)
What is a list?• A list holds items
in order– You can add items
to a list• Added at end
– You can get an item at a position in the list
![Page 10: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/10.jpg)
Creating a List• Go to the
Variables category• Click on "Make a
list"• Give your list a
name– Like answerList
![Page 11: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/11.jpg)
Set-up and ask questions
• When the green flag is clicked– Clear the answer
list• Delete all items
from it
– Ask each question– Add each answer
to the answer list
![Page 12: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/12.jpg)
Displaying the MadLib• You can join two
strings together– Using join tile from
Operators
• You can get an item from a position in the list
![Page 13: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/13.jpg)
Using multiple joins• You can use
more than one join
![Page 14: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/14.jpg)
Final Code
![Page 15: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/15.jpg)
Using variables with strings
• You can make a variable– Like sentence
• You can set the variable to the result of a join– Remember to
include spaces
![Page 16: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/16.jpg)
Challenges• Create an longer madlib• Create a personalized story
– Add user name and other info to the story
• Create an interactive story– Let user pick what to do in the story
![Page 17: Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011](https://reader034.vdocument.in/reader034/viewer/2022051516/56649d985503460f94a81f74/html5/thumbnails/17.jpg)
Summary• You can ask questions in Scratch
– And get the answer
• You can join two strings together– You must add any spacing between
strings
• You can store items in lists– Add, delete, insert, get item at position