diff --git a/docs/lessons/bop-it/quiz-answers.md b/docs/lessons/bop-it/quiz-answers.md index 852602bb..66033d7e 100644 --- a/docs/lessons/bop-it/quiz-answers.md +++ b/docs/lessons/bop-it/quiz-answers.md @@ -12,17 +12,14 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu ## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2 -
- -``` -action = Math.random(3) +```blocks +let action = Math.random(3) ``` ## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0 -
- -``` +```blocks +let action = Math.random(3) if (action == 0) { basic.showString("PUSH A", 150) } @@ -30,10 +27,9 @@ if (action == 0) { ## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1 -
- -``` +```blocks input.onButtonPressed(Button.A, () => { + let action = Math.random(3) if (action == 0) { game.addScore(1) } @@ -42,9 +38,8 @@ input.onButtonPressed(Button.A, () => { ## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1 -
- -``` +```blocks +let action = Math.random(3) if (action == 1) { basic.showString("LOGO DOWN", 150) } @@ -52,10 +47,9 @@ if (action == 1) { ## 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1 -
- -``` +```blocks input.onLogoDown(() => { + let action = Math.random(3) if (action == 1) { game.addScore(1) } @@ -64,9 +58,8 @@ input.onLogoDown(() => { ## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2 -
- -``` +```blocks +let action = Math.random(3) if (action == 2) { basic.showString("SHAKE", 150) } @@ -74,13 +67,11 @@ if (action == 2) { ## 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2 -
- -``` +```blocks input.onLogoDown(() => { + let action = Math.random(3) if (action == 1) { game.addScore(1) } }) ``` - diff --git a/docs/lessons/catch-the-egg-game.md b/docs/lessons/catch-the-egg-game.md index 36ede269..079b6df5 100644 --- a/docs/lessons/catch-the-egg-game.md +++ b/docs/lessons/catch-the-egg-game.md @@ -11,6 +11,7 @@ Variables ## Quick Links * [activity](/lessons/catch-the-egg-game/activity) +* [tutorial](/lessons/catch-the-egg-game/tutorial) * [quiz](/lessons/catch-the-egg-game/quiz) * [quiz answers](/lessons/catch-the-egg-game/quiz-answers) @@ -20,18 +21,21 @@ Learn how to create a catch the egg game game with **plot**, `led->plot` , **unp ## Documentation -* **variables** : [read more...](/reference/variables/var) -* **forever** : [read more...](/reference/basic/forever) -* **unplot** : [read more...](/reference/led/unplot) -* **plot** : [read more...](/reference/led/plot) -* **if** : [read more...](/reference/logic/if) -* **acceleration** : [read more...](/reference/input/acceleration) -* **math minimum number** : [read more...](/reference/math) -* **math maximum number** : [read more...](/reference/math) -* **math random number** : [read more...](/reference/math) -* **math modulus** : [read more...](/reference/math) -* **show number** : [read more...](/reference/basic/show-number) -* **pause** : [read more...](/reference/basic/pause) +```cards +let x = 2; +led.unplot(0, 0); +basic.forever(() => {}); +x += 1; +led.plot(0, 0); +basic.pause(300); +input.acceleration(Dimension.X); +Math.min(0,0); +Math.max(0,1); +Math.random(5); +game.addScore(1); +game.score(); +game.removeLife(1); +``` ## Objectives diff --git a/docs/lessons/catch-the-egg-game/activity.md b/docs/lessons/catch-the-egg-game/activity.md index 61d29db4..e7479558 100644 --- a/docs/lessons/catch-the-egg-game/activity.md +++ b/docs/lessons/catch-the-egg-game/activity.md @@ -1,7 +1,5 @@ # catch the egg game challenges -Coding challenges for catch the egg game. - ## Before we get started Your starting code should look like this: diff --git a/docs/lessons/catch-the-egg-game/tutorial.md b/docs/lessons/catch-the-egg-game/tutorial.md new file mode 100644 index 00000000..3c805b86 --- /dev/null +++ b/docs/lessons/catch-the-egg-game/tutorial.md @@ -0,0 +1,29 @@ +# catch the egg game tutorial + +### Rebuild the game! + +The blocks have been shuffled! Put them back together so that... +* an egg LED falls from the top of the screen, row by row. +* a basket LED is on the bottom row and can be moved by using the accelerometer `X` data. +* if the egg LED reaches the last row, reset the egg position to the first row. + +```shuffle +let basketX = 2 +let eggX = 2 +let eggY = 0 +basic.forever(() => { + led.unplot(basketX, 4) + led.unplot(eggX, eggY) + eggY = eggY + 1 + led.plot(eggX, eggY) + basic.pause(300) + let accX = input.acceleration(Dimension.X) + basketX = 2 + Math.min(2, Math.max(-2, accX / 200)) + led.plot(basketX, 4) + if (eggY > 4) { + eggY = -1 + eggX = Math.random(5) + } + basic.pause(300) +}) +``` diff --git a/docs/lessons/glowing-pendulum.md b/docs/lessons/glowing-pendulum.md index 9fdcaccd..407aeb72 100644 --- a/docs/lessons/glowing-pendulum.md +++ b/docs/lessons/glowing-pendulum.md @@ -9,6 +9,7 @@ Acceleration ## Quick Links * [activity](/lessons/glowing-pendulum/activity) +* [tutorial](/lessons/glowing-pendulum/tutorial) * [challenges](/lessons/glowing-pendulum/challenges) * [quiz](/lessons/glowing-pendulum/quiz) * [quiz answers](/lessons/glowing-pendulum/quiz-answers) diff --git a/docs/lessons/glowing-pendulum/activity.md b/docs/lessons/glowing-pendulum/activity.md index 70845508..209a1a57 100644 --- a/docs/lessons/glowing-pendulum/activity.md +++ b/docs/lessons/glowing-pendulum/activity.md @@ -4,10 +4,29 @@ Construct a pendulum that glows using acceleration. Welcome! This activity will teach how to construct a pendulum that glows using acceleration. Let's get started! +Turn on all the LEDs. + +```blocks +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) +``` + Create a **forever** loop that will constantly display the appropriate brightness on the LED display. ```blocks +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) basic.forever(() => { }) @@ -16,6 +35,13 @@ basic.forever(() => { Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value. ```blocks +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) basic.forever(() => { let acceleration = input.acceleration(Dimension.Y); }); @@ -25,9 +51,15 @@ Since the micro:bit will be swinging back and forth, the acceleration will only ```blocks -let acceleration = 0; +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) basic.forever(() => { - acceleration = input.acceleration(Dimension.Y); + let acceleration = input.acceleration(Dimension.Y); acceleration = Math.abs(acceleration) }); ``` @@ -35,6 +67,13 @@ basic.forever(() => { The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range. ```blocks +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) basic.forever(() => { let acceleration = input.acceleration(Dimension.Y); acceleration = Math.abs(acceleration); @@ -46,37 +85,19 @@ basic.forever(() => { Now let's use our acceleration value to set the brightness on the micro:bit. ```blocks +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) basic.forever(() => { let acceleration = input.acceleration(Dimension.Y); acceleration = Math.abs(acceleration); acceleration = acceleration / 4; led.setBrightness(acceleration) }); - - - -``` - - -Let's show what the brightness of the micro:bit is by turning all the LEDs on! - -```blocks - -basic.forever(() => { - let acceleration = input.acceleration(Dimension.Y); - acceleration = Math.abs(acceleration); - acceleration = acceleration / 4; - led.setBrightness(acceleration) - basic.showLeds(` - # # # # # - # # # # # - # # # # # - # # # # # - # # # # # - `) -}); - - ``` ### ~avatar avatar diff --git a/docs/lessons/glowing-pendulum/tutorial.md b/docs/lessons/glowing-pendulum/tutorial.md new file mode 100644 index 00000000..1bc261d5 --- /dev/null +++ b/docs/lessons/glowing-pendulum/tutorial.md @@ -0,0 +1,29 @@ +# glowing pendulum block tutorial + +The glowing pendulum changes the screen brightness based on the acceleration measured on the BBC micro:bit. + +### Rebuild the game! + +The blocks have been shuffled! Put them back together so that... +* all LEDs are turned on +* the BBC micro:bit repeats code **forever** that + * reads the acceleration along the ``y`` axis, + * calculate the absolute value of the acceleration + * scales down the acceleration value by a factor of `4` + * uses the scaled value to set the screen **brightness** + +```blocks +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) +basic.forever(() => { + let acceleration = input.acceleration(Dimension.Y); + acceleration = Math.abs(acceleration); + acceleration = acceleration / 4; + led.setBrightness(acceleration) +}); +``` diff --git a/docs/lessons/guess-the-number.md b/docs/lessons/guess-the-number.md index 611bd482..7b825d5a 100644 --- a/docs/lessons/guess-the-number.md +++ b/docs/lessons/guess-the-number.md @@ -11,6 +11,7 @@ Math - Pick Random ## Quick links * [activity](/lessons/guess-the-number/activity) +* [tutorial](/lessons/guess-the-number/tutorial) * [challenges](/lessons/guess-the-number/challenges) * [quiz](/lessons/guess-the-number/quiz) * [quiz answers](/lessons/guess-the-number/quiz-answers) diff --git a/docs/lessons/guess-the-number/activity.md b/docs/lessons/guess-the-number/activity.md index a7e2fb4c..d6846948 100644 --- a/docs/lessons/guess-the-number/activity.md +++ b/docs/lessons/guess-the-number/activity.md @@ -19,12 +19,11 @@ 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 `09`. - +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(9) + let x = Math.random(10) }) ``` @@ -34,7 +33,7 @@ Show the random number on the screen. ```blocks input.onButtonPressed(Button.A, () => { - let x = Math.random(9) + let x = Math.random(10) basic.showNumber(x) }) diff --git a/docs/lessons/guess-the-number/tutorial.md b/docs/lessons/guess-the-number/tutorial.md new file mode 100644 index 00000000..3994e00d --- /dev/null +++ b/docs/lessons/guess-the-number/tutorial.md @@ -0,0 +1,25 @@ +# guess the number tutorial + +### ~avatar avatar + +### @video td/videos/guess-the-number-0 + +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) +}) +``` +