Migrate docs from the other repo
This commit is contained in:
130
docs/reference/js/lessons/die-roll/activity.md
Normal file
130
docs/reference/js/lessons/die-roll/activity.md
Normal file
@ -0,0 +1,130 @@
|
||||
# die roll activity
|
||||
|
||||
Create a die on the BBC micro:bit
|
||||
|
||||
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **KindScript**.
|
||||
|
||||
Let's create a condition for when the BBC micro:bit is shaken.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
})
|
||||
```
|
||||
|
||||
We need to show a random value from 1 to 6 on our die. So let's make a local variable called **roll**.
|
||||
|
||||
```
|
||||
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 die that shows 6.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll1 = Math.random(6)
|
||||
if (roll1 == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the die.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll2 = Math.random(6)
|
||||
if (roll2 == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`, 400)
|
||||
} else if (roll2 == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the die. Let's also repeat these steps to show the 3, 2, and 1 on the die. We are almost done with our die!
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll3 = Math.random(6)
|
||||
if (roll3 == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`, 400)
|
||||
} else if (roll3 == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
else if (roll3 == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
else if (roll3 == 2) {
|
||||
basic.showLeds(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`, 400)
|
||||
}
|
||||
else if (roll3 == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
else {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/die-roll/challenges)!
|
||||
|
||||
### ~
|
||||
|
201
docs/reference/js/lessons/die-roll/challenges.md
Normal file
201
docs/reference/js/lessons/die-roll/challenges.md
Normal file
@ -0,0 +1,201 @@
|
||||
# die roll challenges
|
||||
|
||||
Create a die on the BBC micro:bit.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/die-roll/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6) // ***
|
||||
if (roll == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
else if (roll == 1) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Modify the line of code with `math->random` so that only number 1-4 can appear on the die.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll1 = Math.random(4) // ***
|
||||
if (roll1 == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll1 == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll1 == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll1 == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
else if (roll1 == 1) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's make a trick die! Modify the line of code with `math->random` so that only numbers 3-6 can appear on the die. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll2 = Math.random(4) + 2 // ***
|
||||
if (roll2 == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll2 == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 1) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 0) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Add a couple more conditions so that the BBC micro:bit randomly chooses a number between 1 and 8.
|
||||
|
116
docs/reference/js/lessons/die-roll/quiz-answers.md
Normal file
116
docs/reference/js/lessons/die-roll/quiz-answers.md
Normal file
@ -0,0 +1,116 @@
|
||||
# die roll quiz answers
|
||||
|
||||
Create a die when the BBC micro:bit is shaken
|
||||
|
||||
These are the answers to the [die roll quiz](/microbit/lessons/die-roll/quiz).
|
||||
|
||||
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let roll = Math.random(6)
|
||||
```
|
||||
|
||||
## 2. If the variable "roll" equals 5, write the code that will plot the image below
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (roll == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (roll == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (roll == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
} else if (roll == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (roll == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
} else if (roll == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
||||
|
42
docs/reference/js/lessons/die-roll/quiz.md
Normal file
42
docs/reference/js/lessons/die-roll/quiz.md
Normal file
@ -0,0 +1,42 @@
|
||||
# die roll quiz
|
||||
|
||||
Create a die when the BBC micro:bit is shaken
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [die roll tutorial](/microbit/lessons/die-roll/tutorial).
|
||||
|
||||
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
|
||||
|
||||

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

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

|
||||
|
||||
<br />
|
||||
|
||||
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
Reference in New Issue
Block a user