pxt-calliope/docs/lessons/headbands/quiz-answers.md

83 lines
1.6 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# headbands quiz answers
2016-04-02 01:22:47 +02:00
create a charades game with a collection of strings.
2016-03-26 00:47:20 +01:00
## Name
## Directions
2016-04-13 17:27:45 +02:00
Use this activity document to guide your work in the [headbands tutorial](/lessons/headbands/activity).
2016-03-26 00:47:20 +01:00
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What is the meaning of the term 'collection' in programming? What is a 'collection' of strings?
<br/>
A 'collection' is a group of variables of the same type stored together. A 'collection' of strings is a group of strings stored together.
## 2. Consider the following lines of code.
2016-03-31 02:01:28 +02:00
```blocks
2016-07-25 11:35:15 +02:00
let coll: string[] = []
2016-03-26 00:47:20 +01:00
coll.push("puppy")
coll.push("clock")
```
Write the line of code that will display the string "puppy" using `data->coll`.
<br/>
2016-03-31 02:01:28 +02:00
```blocks
let coll: string[] = []
2016-03-26 00:47:20 +01:00
basic.showString(coll[0], 150)
```
## 3. Consider the following lines of code.
2016-03-31 02:01:28 +02:00
```blocks
2016-07-25 11:35:15 +02:00
let coll: string[] = []
2016-03-26 00:47:20 +01:00
coll.push("puppy")
coll.push("clock")
coll.push("cat")
```
Write the line of code that will display the string "cat" using `data->coll`.
<br/>
2016-03-31 02:01:28 +02:00
```blocks
let coll: string[] = []
2016-03-26 00:47:20 +01:00
basic.showString(coll[2], 150)
```
## 4. Consider the following line of code.
2016-03-31 02:01:28 +02:00
```blocks
2016-07-25 11:35:15 +02:00
let coll: string[] = []
2016-03-26 00:47:20 +01:00
```
Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
<br/>
2016-03-31 02:01:28 +02:00
```blocks
2016-07-25 11:35:15 +02:00
let coll: string[] = []
coll.push("puppy")
2016-03-26 00:47:20 +01:00
coll.push("clock")
coll.push("night")
coll.push("cat")
coll.push("cow")
```
## 5. Write the code to get a string from the collection at a random position.
<br/>
2016-03-31 02:01:28 +02:00
```blocks
2016-08-10 23:06:26 +02:00
let coll: string[] = []
2016-03-26 00:47:20 +01:00
let index = Math.random(coll.length)
let word = coll[index]
```