Coding Selections
In this activity you will be given some Scratch code that creates a list of items. Your task is to add some more code that will be able to find a specific word in that list of items by including repetition and selection.
Start with the Scratch code shown below, which creates a list of items.
You can find this code using the following link:
https://scratch.mit.edu/projects/288581584/
Here is what the list looks like
Using the provided code as a starting point, you now need to write some code that looks for a specific item of data in the list by starting at the beginning and working through the list one item at a time. To do this you will need to use the following blocks:
An 'ask' block to get the name of the item from the user. This will automatically create a variable called 'answer' that you can use in your code.
A variable has been created in the Scratch project called 'Item Count'. You will need to use the block that sets this variable to zero before you add any more code.
A 'repeat until' block that uses a variable to count where the code is currently processing the list and finishes when it gets to the end. The variable called 'Item Count' can be used here to set the number of times the block will repeat.
The green blocks in Scratch are known as 'operators' and allow you to compare values.
Inside this loop you will need an 'if' block that checks if the current item is the one the code is looking for. Note that each time this block is used the code is comparing the current item in the list with the word that was typed in by the user.
Inside this loop you need the sprite to tell the user where it found the match. A 'say' block can be used to do this.
You also need to make sure that each time the repeat block executes that the 'Item Count' variable goes up by 1. The following block will do this:
So, your main task is to get all these blocks in the right order so that the algorithm of the code makes logical sense. Good luck!
If you get stuck, you can find an example solution in this Scratch project:
https://scratch.mit.edu/projects/305284560/
Once you have got the code working, try changing the content of the list and make sure it still works as expected.