move lessons out of web site

will move select lessons back to "educators" section
This commit is contained in:
Tom Ball
2016-06-14 11:49:58 -04:00
parent a6e6dd8287
commit f4eca66648
184 changed files with 8 additions and 8 deletions

View File

@ -0,0 +1,169 @@
# dice roll activity
Create a dice on the micro:bit
### ~avatar avatar
Welcome! This tutorial will help you create a dice. Let's get started!
### ~
Let's create a condition for when the micro:bit is shaken.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
We need to show a random value from 1 to 6 on our dice. So let's make a local variable called **roll**.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6)
})
```
We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 because **roll** has a range from 0 to 5. We can use `show LEDs` to display the side of a dice that shows 6.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
});
```
Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the dice.
```blocks
input.onGesture(Gesture.Shake, ()=> {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
});
```
Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the dice.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
});
```
Let's also repeat these steps to show the 3, 2, and 1 on the dice. We are almost done with our dice!
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/dice-roll/challenges)!
### ~

View File

@ -0,0 +1,183 @@
# dice roll challenges
Create a dice on the micro:bit.
## Before we get started
Complete the following [guided tutorial](/lessons/dice-roll/activity), your code should look like this:
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### Challenge 1
Modify the line of code with `pick random` so that only number 1-4 can appear on the dice.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(4);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### Challenge 2
Let's make a trick dice! Modify the line of code with `pick random` so that only numbers 3-6 can appear on the dice. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(4) + 2;
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### Challenge 3
Add a couple more conditions so that the BBC micro:bit randomly chooses a number between 1 and 8.

View File

@ -0,0 +1,121 @@
# dice roll quiz answers
Create a dice when the BBC micro:bit is shaken
These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
<br/>
```blocks
let roll = Math.random(6)
```
## 2. If the variable "roll" equals 5, write the code that will plot the image below
![](/static/mb/lessons/die-roll-0.png)
<br/>
```blocks
let roll = Math.random(6)
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .
`)
}
```
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-1.png)
<br />
```blocks
let roll = Math.random(6)
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .
`)
} else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .
`)
}
```
Note: students are only required to write the bottom half of this answer, starting with "else if".
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-2.png)
<br />
```blocks
let roll = Math.random(6)
if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .
`)
} else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .
`)
}
```
Note: students are only required to write the bottom half of this answer, starting with "else if".
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
![](/static/mb/lessons/die-roll-3.png)
<br />
```blocks
let roll = Math.random(6)
if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .
`)
} else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #
`)
}
```
Note: students are only required to write the bottom half of this answer, starting with "else if".

View File

@ -0,0 +1,42 @@
# dice roll quiz
Create a dice when the BBC micro:bit is shaken
## Name
## Directions
Use this activity document to guide your work in the [dice roll tutorial](/lessons/dice-roll/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
<br/>
## 2. If the variable "roll" equals 5, write the code that will plot the image below
![](/static/mb/lessons/die-roll-0.png)
<br/>
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-1.png)
<br />
<br/>
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-2.png)
<br />
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
![](/static/mb/lessons/die-roll-3.png)
<br />