put lessons back for Michael
This commit is contained in:
45
docs/lessons/guess-the-number/activity.md
Normal file
45
docs/lessons/guess-the-number/activity.md
Normal file
@ -0,0 +1,45 @@
|
||||
# guess the number activity
|
||||
|
||||
Guess the number with math random.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This tutorial will help you create a guess the number game! Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Add an event handler when button `A` is pressed.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Create a local variable of type number `x` and set it to a random number using `pick random`. `pick random` 9 generates a random number between `0` and `9`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Show the random number on the screen.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/guess-the-number/challenges)!
|
||||
|
||||
### ~
|
||||
|
33
docs/lessons/guess-the-number/challenges.md
Normal file
33
docs/lessons/guess-the-number/challenges.md
Normal file
@ -0,0 +1,33 @@
|
||||
# guess the number challenges
|
||||
|
||||
Coding challenges for the guess the number tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/guess-the-number/activity), and your code should look like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(9)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
When button `B` is pressed, we want to clear the screen. This will make it so users can play your game over and over again! Add an event handler to handle this case.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(9)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Show an animation when you clear the screen! Choose what animation makes most sense to you. Be creative!
|
||||
|
41
docs/lessons/guess-the-number/quiz-answers.md
Normal file
41
docs/lessons/guess-the-number/quiz-answers.md
Normal file
@ -0,0 +1,41 @@
|
||||
# guess the number quiz answers
|
||||
|
||||
Learn how to generate a random number on the micro:bit.
|
||||
|
||||
This is the answer key for the [guess the number quiz](/lessons/guess-the-number/quiz).
|
||||
|
||||
## 1. What is on button pressed?
|
||||
|
||||
Answers may vary. Generally, on button pressed run code when an input button is pressed. The micro:bit has two input buttons: A and B.
|
||||
|
||||
## 2. Consider the following directions
|
||||
|
||||
Write the line of code that creates a condition when the BBC micro:bit button A is pressed.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
## 3. Write the line of code that creates a **local variable** and a **random number**.
|
||||
|
||||
|
||||
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.random(10)
|
||||
```
|
||||
|
||||
## 4.
|
||||
If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded.
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.random(10)
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
The random number generator will return a number from 0 to the limit. However, not including the limit unless the limit is 0. So you can place an X to represent any single digit number.
|
||||
|
35
docs/lessons/guess-the-number/quiz.md
Normal file
35
docs/lessons/guess-the-number/quiz.md
Normal file
@ -0,0 +1,35 @@
|
||||
# guess the number quiz
|
||||
|
||||
Learn how to generate a random number on the micro:bit.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [guess the number tutorial](/lessons/guess-the-number/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what "input -> on button pressed" does?
|
||||
|
||||
<br />
|
||||
|
||||
## 2. Write the line of code that creates a condition for on button A pressed.
|
||||
|
||||
<br />
|
||||
|
||||
## 3. Write the line of code that creates a `local variable` called `randomNumber` and will return a number from 0 to a limit of 10.
|
||||
|
||||
<br />
|
||||
|
||||
## 4. Draw the area that could be lit based on the code below. Explain why you chose to draw that number.
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.random(10)
|
||||
basic.showNumber(randomNumber, 150)
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
23
docs/lessons/guess-the-number/tutorial.md
Normal file
23
docs/lessons/guess-the-number/tutorial.md
Normal file
@ -0,0 +1,23 @@
|
||||
# guess the number tutorial
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
This tutorial will help you create a guess the number game! Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* when the user presses button ``A``,
|
||||
* generate a random number
|
||||
* show the number on screen
|
||||
|
||||
|
||||
```shuffle
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
```
|
||||
|
Reference in New Issue
Block a user