updated headbands
This commit is contained in:
91
docs/lessons/headbands/activity.md
Normal file
91
docs/lessons/headbands/activity.md
Normal file
@ -0,0 +1,91 @@
|
||||
# headbands challenges
|
||||
|
||||
These challenges will teach you how to create a fun charades game to play with your friends. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Your beginning code should look like this:
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(30000)
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's add more words for the player to act out! But first, we need to increase the time in one round to give the player more time get through all the words. Let's change the `game->start countdown` statement.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
game.addScore(1)
|
||||
})
|
||||
|
||||
game.startCountdown(60000)
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now let's add 5 more words to our list of charade words. Right above the the line `word:=coll->at(index)` add 5 lines that say `coll->add("")`. In this example, we will add the words **bicycle, telephone, sun, car, and ant** but you can add whatever words you like.
|
||||
|
||||
```blocks
|
||||
let coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
coll.push("bicycle")
|
||||
coll.push("telephone")
|
||||
coll.push("sun")
|
||||
coll.push("car")
|
||||
coll.push("ant")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(30000)
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Remove a life using `game->remove life` when the screen is down using the `input->on screen down` event.
|
||||
|
||||
### Challenge 4
|
||||
|
||||
The collection has a function `random` that returns a random element. Update your code to use this function instead of using `math->random`.
|
||||
|
||||
### Challenge 5!
|
||||
|
||||
Play the game and try guessing all these words in less than 2 minutes!
|
||||
|
78
docs/lessons/headbands/quiz-answers.md
Normal file
78
docs/lessons/headbands/quiz-answers.md
Normal file
@ -0,0 +1,78 @@
|
||||
# headbands quiz answers
|
||||
|
||||
create a charades game with a collection of strings #offset #screen #variables #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [headbands tutorial](/microbit/lessons/headbands/activity).
|
||||
|
||||
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.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
```
|
||||
|
||||
Write the line of code that will display the string "puppy" using `data->coll`.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
basic.showString(coll[0], 150)
|
||||
```
|
||||
|
||||
## 3. Consider the following lines of code.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("cat")
|
||||
```
|
||||
|
||||
Write the line of code that will display the string "cat" using `data->coll`.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
basic.showString(coll[2], 150)
|
||||
```
|
||||
|
||||
## 4. Consider the following line of code.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
```
|
||||
|
||||
Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let coll.push("puppy")
|
||||
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/>
|
||||
|
||||
```blocks
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
```
|
||||
|
63
docs/lessons/headbands/quiz.md
Normal file
63
docs/lessons/headbands/quiz.md
Normal file
@ -0,0 +1,63 @@
|
||||
# headbands quiz
|
||||
|
||||
create a charades game with a collection of strings #offset #screen #variables #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [headbands tutorial](/microbit/lessons/headbands/activity).
|
||||
|
||||
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/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code that will display the string "puppy" using "data->coll".
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the line of code that will display the string "cat" using `"data->coll".
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("cat")
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
|
||||
```
|
||||
let coll = (<string[]>[])
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code to get a string from the collection at a random position.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
Reference in New Issue
Block a user