Collecting Your Data

This page should probably be split into two or three pages. --MF, 1/11/23

In this activity, you will gather responses to your survey questions.

The data you collect will be stored as table. As you collect data, the list will fill up with additional rows, but the survey questions will remain as the first row of the survey. For example:
'my survey' watcher: a table with four rows and two columns. Row 1 column 1 has the text: 'How many years have you been playing music?' and row 1 column 2 has the text: 'How many hours do you listen to music each day?' Row 2 has the values '6' and '1'. Row 3 has the values '0' and '3'. Row 4 has the values '2' and '1.5'.

The questions only from survey 'list input slot' block takes a survey as input and reports its first row with all the questions.
 questions only from survey (my survey) reporting the list {How many years have you been playing music?, How many hours do you listen to music each day?}

Asking the User a Question

Next version, change name to ask question. --MF, 12/28/21 and PF

This project also includes an ask () block that takes a question as input, asks the user the question, and reports the user's response.

  1. If your project isn't open already, log in to Snap!, and open your "Data Dos" project.
  2. Talk with Your Partner Look at the code inside the questions only block, and discuss how the block works (even when the survey is full of data).
    Each row in a table is a list of items, and item of selects one. You learned about item of in Lab 4 Activity 3.
  3. Type a question into the ask block, and then click it to see how the responses will be entered into Snap! and then reported by the ask block.

    How does ask () work?

    ask (question) {
	ask (question) and wait
	report (answer)
}

    The ask block takes a question as input, asks the user the question, waits for a response, and then reports the user's response as the output of the function.

  4. Talk with Your Partner What kinds of tools do you still need in order to use questions only and ask together to ask the user each question from your survey and store that data in the my survey variable?

Adding New Responses to Your Table

The missing tool is the map 'reporter input slot' over 'list input slot' block, which performs an action to each item in a list. In this case, the action is to ask the user, and the list is the output of questions only from my survey.

You learned about the map block in Lab 4 Activity 4: Transforming Every Pixel.
  1. Complete the block definition for new response for 'list input slot' so that it takes a survey as input, asks the user each question in the survey, and reports a list of the user's responses. Test the block, and make sure it works before moving on to the next step: adding the user responses to the survey.
    You'll need to drag the my survey variable out of the palette on the left and into the empty input slot.
    new response for (my survey) reporting the list {soccer, 3}

    Click for a hint about building new response.

    Use map together with ask and questions only.

The new response block reports the user's data, but it doesn't send it anywhere. The add () to 'list input slot' block will take data and add it the end of a list.
'my survey' watcher: a table with three rows and two columns. Row 1 column 1 has the text: 'Favorite sport?' and row 1 column 2 has the text: 'Years played?' Row 2 has the values 'soccer' and '4'. Row 3 has the values 'basketball' and '3'. 'my survey' watcher: a table with three rows and two columns. Row 1 column 1 has the text: 'Favorite sport?' and row 1 column 2 has the text: 'Years played?' Row 2 has the values 'soccer' and '4'. Row 3 has the values 'basketball' and '3'. Row 4 has the values 'soccer' and '5'.

  1. Use new response together with add to create code to collect survey data.
  2. Try adding a few test responses to your survey, and notice how the watcher updates with your added data.

Collecting Data

  1. Once everything is working, clear the test data from your survey.
    You can remove the data from the survey either by:
    • Using reset survey and then running the survey setup script again
    • Using delete () from 'list input slot' to remove the testing rows one at a time until only the row of questions is left. (The delete block takes a position number and a list as input and removes the item from the list at the specified position number.)
  2. Collect data from several people using your code to input their responses into your survey.
  3. Now Is a Good Time to Save

In this activity, you learned about the ask and add blocks and used them together with map to collect data for your survey.