CS 1150 PEEE   Scratch: Trivia (Using Data Lists)

(using blocks and variables)

Overview and Specifications

Your familiarity with Scratch and with programming should be allowing you to feel more comfortable as you program. Hopefully, you are gaining facility with data and variables. This programming activity should provide additional experience with data and variables and introduce the key idea of data collections (lists in Scratch). Additionally it provides an example of another activity your students would enjoy—quizzing their friends. This document has two parts—the specifications for the assignment and information that should help you better understand how do to the assignment.

I would like you to produce a program that uses at least two lists of data, preferably parallel lists. Other data may also be useful. A common way to do this is to decide upon some sort of quiz or trivia contest where the questions are in one list and the answers in another list, e.g., the capitals quiz referred to in the background information below. You could do something similar (but more interesting or fun). Whatever you choose as a topic, your program should use lists and interact with the user.

As usual, the recommended first step in this assignment is to consider what you want to do—the questions and answers in your program and the context you want to use, e.g., a trivia contest, quiz with "normal" questions and answers or Jeopardy-like, etc.

The program you plan and implement should meet the expectations below.

You are encouraged to go beyond the minimal expectations, e.g.,

Grades higher than a C will require including one the above "optional" elements. Higher grades will require more than one.

Submitting Your Work

When you are finished with your program you will want to share it with the class by placing it in our studio. That process involves:

That should be all it takes to "submit" the program. Whichever partner submitted the program should have the other partner sign in to Scratch and double check that the project is available in the studio. Don't forget that both partners are to complete the PAC commenting together.

Note that you should always be able to get back to the project page or to the Scratch programming environment from which you can access the project page. If you joined Scratch, your projects should all be available and be saved regularly by the system.


I will be checking the programs to see if they meet the specifications (noted above). A program that minimally meets all the specs is at least "okay" (i.e., a C). Better programs will go beyond the the minimal specs; some suggestions are noted above. Commenting your code and "cleaning up" the script area also improve the quality of your program. Creating new blocks/modules for duplicate code also improves program quality.

Some Background Information

Uploading List Values

scratch script for repeatedly adding data to a list via an ask blockAfter creating a list, you can enter the data by clicking on the little plus icon in the list and typing data. Pressing the Return/Enter key will cause another item to be added to the list and you can type and press Enter for each of the rest of the data values to be put in the list. There is also a block that will add values to the list (at the end). A code snippet to do that is shown to the right.

An alternative to typing the data is to find or create a file that can be uploaded. For example, I searched the web for a list of states and capitals, copies the data into Excel, separated the data into two different sheets, and saved each one as a .csv (comma separated values) list. Then I could upload the list to Scratch. To do that:

Your list should automatically get populated. Double check to make sure that any blank lines at the beginning or end don't cause an empty item in your list. If there is one, just click on the empty item and then click the  x  icon.

Presenting Randomly Selected Items (With Parallel Lists)

scratch script for selecting, asking, and checking a random trivia itemTypically, a trivia game or app will choose its items randomly. Scratch has an operator called pick random ... for this purpose. If we have a list of items all we need to do is have the computer choose a random number between 1 (the first position in the list) and however many items are in the list. Scratch provides a data value for that—the length of [...] block. The code at the right will pick an item to present, present the item and check to see if you the user answered correctly.

Look the present-a-random-trivia-item script over carefully. You should see:  1) how the random number is picked and why it will always refer to one of the list items,  2) that the random value is saved in a variable,  3) that/how the variable causes matching values from the lists to be used,  4) how correctness of the response is determined and reported. If you have any question, be sure to ask.


Your program is expected to report the number of answered correctly and its percentage equivalent. There are three numbers involved in tracking results such as this—number of items presented;  number of items correct;  and number of items incorrect. Any two of them will allow you to present your results. Keep in mind that the percent correct value is calculated as shown below.

	 # correct
	----------- X 100
	# presented

(We multiply by 100 and put on a percent sign to avoid making people do that themselves.) Note, if you are tracking the number of items correctly answered, you will need to adjust that value at the appropriate time/place in your code. similarly the number of items presented must be adjusted appropriately.


As noted above, you need to know two of three values to do your reporting, but they can do double duty. You could, for example, use the variable for # presented to control when you quit presenting items. For example, if we want to present one fourth of the items that exist we could use a loop like the one below. Note that since we are presenting random items, we might have repeated some and not actually seen 1/4 of the items one time each.
scratch repeat block to stop after presenting 1/4 of the items

Note also, the need to test for both "greater than" or "equal to". If the value being tested is an integer, the greater than would give us one too many items. If the value being tested was not an integer, the repetition would never stop.

Presenting all the items

Randomly selecting and presenting items is useful but makes it harder, but not impossible, to tell if you have presented all the items. There are at least two ways to make sure you present all the items.

One way is to keep track of the location of the last item that has not yet been shown. Then you remove/delete the currentItem from the list and add it to the list (at the end, which thankfully is where Scratch inserts things in lists). After the deletion, the position of the last item in the list has to be reduced by 1. When picking a random value for which item to present, instead of choosing between 1 and the length of the list, choose a number between 1 and lastUnshown, e.g.,
scratch block for picking a random value between 1 and the last value not shown
Note that you will need to delete and move both the question and answer components to the ends of their lists—have to maintain their being parallel lists.

scratch script to initialize a list indicating which values have been presentedAn alternative to this approach is to create a list that indicates whether each item has been shown. It would require creating a list (e.g., shown) and initializing each item in the list to "no" (or whatever negative value you like). The code for initializing the list is shown to the right. We will want this to be part of our initialization which will run each time the green flag is clicked. Remember, however, that after you run a program in Scratch it maintains the status when it quit. This means after the first run (in our states & capitals program) shown will have 50 items. There is no Scratch instruction to delete a variable or list, so the first time we run the program we need to add items to the list (setting them to "no") and thereafter we just want to set each item to "no". Look over the code to see if you fully understand it. If you do not, ask a question in class.

Once the list is initialized, all you have to do is remember to change the appropriate list item to "yes" (or whatever value you like) whenever you present a list item, i.e.,
scratch block for reseting the state for 'shown'