Accessing Your Data

In this activity, you'll build blocks to help you access specific data from your table.

As you process the data in your my survey table, it will be helpful to be able to separate the questions from the responses.
a table with four rows and two columns. Row 1 has the values: 'Favorite sport?' and 'Years played?'. Row 1 is circled and labeled 'Questions only,' and the remaining three rows are circled together and labeled 'Responses only.' Row 2 has the values: 'soccer' and '4'. Row 3 has the values 'basketball' and '3'. Row 4 values: 'soccer' and '5'.

You already have a questions only from survey 'list input slot' block that takes a survey as input and reports the first row (the questions). Click for an example.

 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?}

The code inside questions only uses item of, which reports one item in a list. Click to see the code inside.

questions only from survey (survey data) {
	report (item (1) from (survey data))
}

The responses only from survey 'list input slot' block should report everything but the first row (the responses). Click for an example.

responses only from survey (my survey) reporting a table with three rows and two columns. Row 1 has the values: 'soccer' and '4'. Row 2 has the values 'basketball' and '3'. Row 3 values: 'soccer' and '5'.

To make it work, you can use all but first of 'list input slot', which takes a list as input and reports everything except the first item. Click for an example.

all but first of (list (apple) (banana) (carrot) (daikon)) reporting the list {banana, carrot, daikon}

In Snap!, a table is a list of lists. So for a table, all but first will report everything except the first row.

Reminder: To get another my survey variable, you can either drag one out of the palette on the left or right-click (or control-click on a Mac) one that you already have and choose "duplicate."
  1. If your project isn't open already, log in to Snap!, and open your "Data Dos" project.
  2. Click for a hint.

    The responses are all but the first row of the table.

  3. Complete the block definition for the responses only from survey 'list input slot' block so that it takes a survey as input and reports the survey responses.
  4. Test the responses only block with your survey data, and make sure it works as intended.

You'll also need a way to access a single column of data. In Snap!, table data are stored as a list of lists. So, a column is a list of the items at a specific position in every row.

'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 as the values 'soccer' and '4'. Row 3 as the values 'basketball' and '3'. Row 4 as the values 'soccer' and '5'.
  1. Complete the block definition for responses to question () from survey data 'list input slot'. It takes a question number (the position number of one question) and a survey as input, and it should report all the responses to that question (but not the question itself).
    responses to question (2) from survey (my survey) reporting the list {4, 3, 5}

    Click for hints about creating the responses to question block.

      Talk with Your Partner
    • What function allows you to performs an action to each item in a list?
    • What function will allow you to process all the responses but not the questions? Where does that function need to be used?
    • What function needs to be applied to each item in the list of responses?

    Need another hint?

    Review how the map block works. You used it on the previous page.

  2. Test the responses to question block with your survey data, and make sure it works as intended.
  3. Now Is a Good Time to Save
In this activity, you created a block to access all but the first row of your survey data (just the responses) and a block to access a single column from your survey data (all the responses to a specific question).