update random range to randint (#2993)

* update random range

* fix typo I noticed while sanity checking

Co-authored-by: Richard Knoll <riknoll@users.noreply.github.com>
This commit is contained in:
Joey Wunderlich 2020-06-11 16:44:01 -07:00 коммит произвёл GitHub
Родитель a090b41289
Коммит 1d91100f4d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
75 изменённых файлов: 368 добавлений и 367 удалений

Просмотреть файл

@ -18,10 +18,10 @@ When you compare two Numbers, you get a Boolean value, such as the comparison `x
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.randomRange(0, 5)
let x = randint(0, 5)
if(x < 5) {
basic.showString("low");
} else {
} else {
basic.showString("high");
}
})

Просмотреть файл

@ -5,7 +5,7 @@
Sometimes there is code you want to run if two or more conditions are true. The ``||logic:if then||`` block lets you combine conditions with the ``||logic:and||`` and the ``||logic:or||`` blocks. For example, if we want to see if a random number is between `0` and `9`, we can put two conditions in an ``||logic:if then||`` and connect them with an ``||logic:and||``.
```blocks
let rando = Math.randomRange(-20, 20)
let rando = randint(-20, 20)
if (rando >= 0 && rando < 10) {
basic.showNumber(rando)
}
@ -14,7 +14,7 @@ if (rando >= 0 && rando < 10) {
This is how to check if a result is within a range of values, in this case it's from `0` to `9`. What if we want to include the values between `15` and `18` too? We just add another range check and connect them with an ``||logic:or||``.
```blocks
let rando = Math.randomRange(-20, 20)
let rando = randint(-20, 20)
if ((rando >= 0 && rando < 10) || (rando >= 15 && rando < 18)) {
basic.showNumber(rando)
}
@ -23,7 +23,7 @@ if ((rando >= 0 && rando < 10) || (rando >= 15 && rando < 18)) {
Having all of these conditions in one ``||logic:if then||`` makes a large and complicated block. It can be hard to see how the complete conditional does both of the range checks. At times, it's easier to read the code in the JavaScript editor to better see the order and connections of the conditions.
```typescript
let rando = Math.randomRange(-20, 20)
let rando = randint(-20, 20)
if ((rando >= 0 && rando < 10) || (rando >= 15 && rando < 18)) {
basic.showNumber(rando)
}
@ -36,7 +36,7 @@ As you can see, reading the code for this conditional is might seem easier in Ja
If one ``||logic:if then||`` block is placed inside another, then each condition for checking the random number is placed in its own ``||logic:if then||``. This give the same result as before with the two conditions in the ``||logic:if then||``.
```block
let rando = Math.randomRange(-20, 20)
let rando = randint(-20, 20)
if (rando >= 0) {
if (rando < 10) {
basic.showNumber(rando)
@ -47,7 +47,7 @@ if (rando >= 0) {
When we switch the editor to JavaScript view, we see that the second ``if ()`` statement is indented and contained inside the `{ }` of the first. This matches the second ``||logic:if then||`` block that fits inside the first one. These are called _nested_ if statements.
```typescript
let rando = Math.randomRange(-20, 20)
let rando = randint(-20, 20)
if (rando >= 0) {
if (rando < 10) {
basic.showNumber(rando)
@ -138,4 +138,4 @@ To set the variable based on the result of the expression, the value options are
let heatMessage = input.temperature() < 10 ? "COLD" : "WARM"
```
The ``heatMeassage`` variable is set to the string saying ``"COLD"`` if the temperature is less than `10` degrees celsius or to ``"WARM"`` when it's `10` degrees or warmer.
The ``heatMeassage`` variable is set to the string saying ``"COLD"`` if the temperature is less than `10` degrees celsius or to ``"WARM"`` when it's `10` degrees or warmer.

Просмотреть файл

@ -6,12 +6,12 @@ Create an array of words that can be used as part of a charades-type game.
This activity is based on a very popular phone app invented by Ellen DeGeneres (https://bits.blogs.nytimes.com/2013/05/03/ellen-degeneres-iphone-game/).
![Heads up game](/static/courses/csintro/arrays/headband-charades.png)
* Create a new variable and give it a name like arrayWords.
* Insert a 'set' variable block into the 'on start' block.
* Insert a 'set' variable block into the 'on start' block.
* Change the default variable name to this new variable name.
* From the Array Toolbox drawer, drag an 'array of' block to the coding workspace.
* Attach this array block to the end of the 'set' variable block.
* Attach this array block to the end of the 'set' variable block.
```blocks
let arrayWords = ["", ""]
@ -28,12 +28,12 @@ let arrayWords = ["", "", "", "", "", "", ""]
```
* Fill each string with one word. Choose words that will be fun for a game of charades. Example:
```blocks
```blocks
let arrayWords = ["cat", "guitar", "flashlight", "cupcake", "tree", "frisbee"]
```
Now, we need a way to access one word at a time from this array of words.
* We can use the 'show string' block from the Basic Toolbox drawer, and the 'on screen up' event handler from the Input Toolbox drawer (this is a drop-down menu choice of the 'on shake' block) to tell the micro:bit to display a word when we tilt the micro:bit up.
* We can use the 'show string' block from the Basic Toolbox drawer, and the 'on screen up' event handler from the Input Toolbox drawer (this is a drop-down menu choice of the 'on shake' block) to tell the micro:bit to display a word when we tilt the micro:bit up.
* For this version, well display the words one at a time in the order they were first placed into the array.
* Well use the index of the array to keep track of what word to display at any given time, so you'll need to create an 'index' variable.
@ -89,7 +89,7 @@ input.onGesture(Gesture.ScreenDown, () => {
We have a limited number of elements in our array, so to avoid an error, we need to check and make sure we are not already at the end of the array before we change the index.
 
* Under the Arrays Toolbox drawer, drag out a 'length of' block. The 'length of' block returns the number of items (elements) in an array. For our array, the length of block will return the value 6.
* But because computer programmers start counting at zero, the index of the final (6th) element is 5.
* But because computer programmers start counting at zero, the index of the final (6th) element is 5.
 
Some pseudocode for our algorithm logic:
* When the player places the micro:bit screen down:
@ -141,9 +141,9 @@ input.onGesture(Gesture.ScreenDown, () => {
## Game Play
There are different ways you can play charades with our program. Here is one way you can play with a group of friends.
* With the micro:bit on and held so Player A cannot see the screen, another player starts the program to see the first word.
* With the micro:bit on and held so Player A cannot see the screen, another player starts the program to see the first word.
* The other players act out this word charades-style for Player A to guess.
* When Player A guesses correctly or decides to pass on this word, a player places the micro:bit screen down.
* When Player A guesses correctly or decides to pass on this word, a player places the micro:bit screen down.
* When ready for the next word, a player turns the micro:bit screen up. Play continues until all the words in the array have been used.
 
## Mod this!
@ -197,15 +197,15 @@ Review the use of the random block in the Math category.
* Create a block that will plot a single dot at a random location on the screen by choosing a random number from 0 to 4 for the x axis and a random number from 0 to 4 for the y axis.
```blocks
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
led.plot(randint(0, 4), randint(0, 4))
```
Next, lets create a loop that will repeat the above code five times, for a constellation with five stars.
```blocks
for (let index = 0; index <= 4; index++) {
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
}
led.plot(randint(0, 4), randint(0, 4))
}
```
Note that to keep things simple we dont check for duplicates, so its possible you may end up with fewer than five visible stars. Thats okay.
@ -233,13 +233,13 @@ To fix this, we need to do a little math by subtracting 1 from whatever the valu
let list = [5, 2, 1, 3, 4]
for (let index = 0; index < list[0] - 1; index++) {
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
led.plot(randint(0, 4), randint(0, 4))
}
```
The above code takes the first value in the array and creates that many stars at random locations. Now, all we need to do is iterate through the entire array and do the same thing for each of the values. We will put the above code inside another loop that will run the same number of times as the length of the array (in this case, 5). You should also use a 'pause' block and a 'clear screen' block in between each constellation.
Finally, you might attach the code that shows the constellations to an 'on button A pressed' event handler.
Finally, you might attach the code that shows the constellations to an 'on button A pressed' event handler.
Here is the complete program.
@ -248,7 +248,7 @@ let list: number[] = []
input.onButtonPressed(Button.A, () => {
for (let i = 0; i <= list.length - 1; i++) {
for (let j = 0; j <= list[i] - 1; j++) {
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
led.plot(randint(0, 4), randint(0, 4))
}
basic.pause(1000)
basic.clearScreen()

Просмотреть файл

@ -18,8 +18,8 @@ In this activity, you will demonstrate different kinds of sorting methods on you
* Ask the Sorter to place the students in order by directing them to move, one at a time, to the proper place.
* Once the students are sorted, ask students the following:
>*  How did she sort you into the right order?
* Did you see a pattern?
>*  How did she sort you into the right order?
* Did you see a pattern?
* What did she do?
 
Try to get students to be as precise as possible in explaining their thinking. Sometimes it helps to put the steps on the board, in an algorithm:
@ -62,7 +62,7 @@ let column = 0
let index = 0
input.onButtonPressed(Button.AB, () => {
for (let index = 0; index <= 4; index++) {
list[index] = Math.randomRange(0, 5) + 1
list[index] = randint(0, 5) + 1
}
})
input.onButtonPressed(Button.B, () => {
@ -142,7 +142,7 @@ input.onButtonPressed(Button.B, () => {
})
input.onButtonPressed(Button.AB, () => {
for (let index = 0; index <= 4; index++) {
list[index] = Math.randomRange(0, 5) + 1
list[index] = randint(0, 5) + 1
}
})
input.onButtonPressed(Button.A, () => {
@ -223,7 +223,7 @@ input.onButtonPressed(Button.A, () => {
})
input.onButtonPressed(Button.AB, () => {
for (let index = 0; index <= 4; index++) {
list[index] = Math.randomRange(0, 5) + 1
list[index] = randint(0, 5) + 1
}
})
input.onButtonPressed(Button.B, () => {

Просмотреть файл

@ -2,7 +2,7 @@
![Two-Player Game Example Board](/static/courses/csintro/booleans/two-player.jpg)
This is an assignment for students to come up with a micro:bit program that uses Boolean variables, Boolean operators, and possibly the random function.
This is an assignment for students to come up with a micro:bit program that uses Boolean variables, Boolean operators, and possibly the random function.
 
## Input
Remind the students of all the different inputs available to them through the micro:bit.
@ -205,7 +205,7 @@ let player1Turn = false
let spin = 0
let delay = 0
input.onGesture(Gesture.Shake, () => {
if (player1Turn == true && Math.randomRange(0, 4) < 3) {
if (player1Turn == true && randint(0, 4) < 3) {
basic.clearScreen()
delay = 0
while (delay < 500) {
@ -250,7 +250,7 @@ input.onGesture(Gesture.Shake, () => {
} else if (player1Turn) {
basic.showString("Crash!")
player1Turn = false
} else if (Math.randomRange(0, 4) < 3) {
} else if (randint(0, 4) < 3) {
basic.clearScreen()
delay = 0
while (delay < 500) {
@ -298,7 +298,7 @@ input.onGesture(Gesture.Shake, () => {
}
})
basic.forever(() => {
})
delay = 0
spin = 0
@ -314,7 +314,7 @@ Here is a portion of the board game's code. A boolean variable is used to determ
```blocks
let player1Turn = false;
input.onGesture(Gesture.Shake, () => {
if (player1Turn == true && Math.randomRange(0, 4) < 3) {
if (player1Turn == true && randint(0, 4) < 3) {
}
})
@ -353,4 +353,4 @@ Have students write a reflection of about 150–300 words, addressing the follow
**4 =** Reflection piece addresses all prompts.<br/>
**3 =** Reflection piece lacks 1 of the required elements.<br/>
**2 =** Reflection piece lacks 2 of the required elements.<br/>
**1 =** Reflection piece lacks 3 of the required elements.
**1 =** Reflection piece lacks 3 of the required elements.

Просмотреть файл

@ -1,6 +1,6 @@
# Activity: Rock, paper, scissors
For this activity, each student will need a micro:bit.
For this activity, each student will need a micro:bit.
Everyone will create the same program, the classic rock paper scissor game.
![Rock, paper, scissors](/static/courses/csintro/conditionals/rock-paper-scissors-items.png)
@ -14,7 +14,7 @@ Everyone will create the same program, the classic rock paper scissor game.
>Example pseudocode:<br/>
On button A press: choose random number from 0-2
If random number = 0, then display rock icon,
Else if random number = 1, then display paper icon,
Else if random number = 1, then display paper icon,
Else display scissors icon.
* Point out that because there are only three possibilities, we dont need to do a separate check to see if random number = 2. So we just use an else.
@ -34,7 +34,7 @@ Here's an example mod:
```blocks
let hand = 0
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(0, 3)
hand = randint(0, 3)
if (hand == 0) {
basic.showLeds(`
# # # # #

Просмотреть файл

@ -2,7 +2,7 @@
![Close-up of game tokens](/static/courses/csintro/conditionals/game-pieces.jpg)
This is an assignment for students to create a board game. It should take two to three class periods. If your school has a makerspace or an art classroom where students can access materials such as cardboard, poster paints, or markers, you might schedule your classes to work there.
This is an assignment for students to create a board game. It should take two to three class periods. If your school has a makerspace or an art classroom where students can access materials such as cardboard, poster paints, or markers, you might schedule your classes to work there.
Once students have finished the first version of their games, schedule time for students to play each others games. Ideally, give them some time to give and gather feedback, then revise their games accordingly.
@ -24,7 +24,7 @@ Students will need to work together to come up with:
* A program for the micro:bit
* Photo documentation of the different game pieces, cards, or other components of the game with the micro:bit included as well as a screenshot of your micro:bit code. Each photo must have a caption that describes what the photo is documenting.
* Reflection: A text entry describing your teams game making process and each teammates part in the creation of the game from brainstorming ideas, through construction, programming, and beta testing.
The micro:bit needs to work in conjunction with the game board and/or game pieces and should be a central feature of the game. Ideally, it should be more than a simple substitute for a six-sided die.
The micro:bit might:
@ -34,17 +34,17 @@ The micro:bit might:
* Point randomly at players and kill them
* Display a dynamic score
* ... let your imaginations run wild!
Ideally, students should be writing their own versions of micro:bit programs to do something original.
Ideally, students should be writing their own versions of micro:bit programs to do something original.
Here is one simple program to discuss and use as an example:
![Close-up of game tokens](/static/courses/csintro/conditionals/battle-pieces.jpg)
### Battle pieces
In this example, pieces start out at full strength and lose points based on random events on the board. When two pieces meet on the same space, they battle.
* Press A to enter the strength of piece A.
* Then press B to enter the strength of piece B.
In this example, pieces start out at full strength and lose points based on random events on the board. When two pieces meet on the same space, they battle.
* Press A to enter the strength of piece A.
* Then press B to enter the strength of piece B.
* Shake the micro:bit to determine the winner of the battle, which is proportionately random to the strength of each piece.
```blocks
@ -59,7 +59,7 @@ input.onButtonPressed(Button.B, () => {
basic.showNumber(p2)
})
input.onGesture(Gesture.Shake, () => {
if (Math.randomRange(0, p1 + p2 - 1 + 1) + 1 <= p1) {
if (randint(0, p1 + p2 - 1 + 1) + 1 <= p1) {
basic.showString("A")
} else {
basic.showString("B")
@ -78,7 +78,7 @@ https://www.youtube.com/watch?v=byngcwjO51U
## Beta Testing
Give students a chance to play each others games. The following process works well:
* Have each pair of students set up their own project at their table.
* Have each pair of students set up their own project at their table.
* Leave a clipboard or a laptop on the table for taking notes.
* Rotate the students through each project, moving clockwise around the room:
>* Play the game (5 min)
@ -89,7 +89,7 @@ Sample Survey questions
* What is something about this project that works really well?
* What is something that would make this project even better?
* Any other comments or suggestions?
Many online survey tools will allow you to sort the comments by project and share them with project creators so they can make improvements based on that feedback.
## Reflection
@ -108,13 +108,13 @@ Space Race by K. and S.
>**1** - Shake the micro:bit to randomize how far you get to advance.<br/>
**2** - If you land on a pink square, press “B” on the micro:bit until your previous roll number appears. Then press A and B at the same time to see whether or not you move based upon the number on the square.<br/>
**3** - Up to four players.
![Space race game](/static/courses/csintro/conditionals/space-race.jpg)
Finished game
![micro:bit holder square](/static/courses/csintro/conditionals/microbit-holder.jpg)
micro:bit holder
![Game pieces](/static/courses/csintro/conditionals/game-pieces.jpg)
Game pieces
@ -126,10 +126,10 @@ let previous_roll = 0
input.onButtonPressed(Button.AB, () => {
previous_roll = 0
if (4 <= previous_roll) {
yes_or_no = Math.randomRange(0, 8)
yes_or_no = randint(0, 8)
}
if (4 > previous_roll) {
yes_or_no = Math.randomRange(0, 5)
yes_or_no = randint(0, 5)
}
if (2 < yes_or_no) {
basic.showString("YES")
@ -140,7 +140,7 @@ input.onButtonPressed(Button.AB, () => {
}
})
input.onGesture(Gesture.Shake, () => {
current_roll = Math.randomRange(0, 6)
current_roll = randint(0, 6)
basic.showNumber(current_roll + 1)
basic.pause(5000)
basic.clearScreen()
@ -155,7 +155,7 @@ input.onButtonPressed(Button.A, () => {
})
basic.showString("SPACE RACE")
previous_roll = 0
```
```
## Assessment
@ -188,7 +188,7 @@ previous_roll = 0
`*` JavaScript includes comments in code<br/>
**3 =** micro:bit program lacks 1 of the required elements.<br/>
**2 =** micro:bit program lacks 2 of the required elements.<br/>
**1 =** micro:bit program lacks 3 of the required elements.
**1 =** micro:bit program lacks 3 of the required elements.
### Photo documentation
@ -205,6 +205,6 @@ previous_roll = 0
`*` Beta testing<br/>
**3 =** Reflection piece lacks 1 of the required elements.<br/>
**2 =** Reflection piece lacks 2 of the required elements.<br/>
**1 =** Reflection piece lacks 3 of the required elements.
**1 =** Reflection piece lacks 3 of the required elements.

Просмотреть файл

@ -1,6 +1,6 @@
# Activity: Animation and patterns
Guide the students to create programs using coordinates and LEDs. Each of these short exercises demonstrates how to use coordinates to control the LEDs. These programs can then be modified and used in the students more complex projects.
Guide the students to create programs using coordinates and LEDs. Each of these short exercises demonstrates how to use coordinates to control the LEDs. These programs can then be modified and used in the students more complex projects.
 
* Smile animation - A short exercise in plotting and toggling LEDs to create a simple animation.
* Random Patterns generator - A short exercise using a loop to generate random LED patterns and then checking the status of a specific LED.
@ -35,7 +35,7 @@ basic.showLeds(`
>* Tip: you can also right-click on a block and select Duplicate to copy blocks
* Have the students compare the two face images and determine which LEDs are on in both images.
* Have the students compare the two face images and determine which LEDs are on in both images.
* Plot these LEDs using the correct (x,y) coordinates.
* When done, place these 'plot x y' blocks inside an 'on start' block.
@ -50,10 +50,10 @@ led.plot(3, 3)
Now we can code for the 4 LEDs that change back and forth, on and off, as we switch from one face to the other and back again over and over.
* From the LED Toolbox drawer, drag out 4 'toggle x y' blocks.
* Replace the default values with the correct (x,y) coordinates.
* From the LED Toolbox drawer, drag out 4 'toggle x y' blocks.
* Replace the default values with the correct (x,y) coordinates.
The 'toggle x y' block will change the status of an LED from on to off or off to on.
* Place these 4 'toggle x y' blocks in a 'forever' block.
* Place these 4 'toggle x y' blocks in a 'forever' block.
* Place the two 'toggle x y' blocks that create the smile first, followed by the two 'toggle x y' blocks for the non-smile.
* You may notice that the toggling happens too quickly. Lets slow it down a bit by placing a 'pause' block between the two pairs of 'toggle x y' blocks. Set the pause value to 250 milliseconds.
@ -84,13 +84,13 @@ https://www.youtube.com/watch?v=qqBmvHD5bCw
### ~
## Mod this!
* Add a third image to the animation, perhaps a frown face.
* Add a third image to the animation, perhaps a frown face.
* Make your own custom animation! What LEDs stay the same and which need to be toggled?
 
## Random patterns generator
A short exercise using a loop to generate random LED patterns and then checking the status of a specific LED.
Pseudocode:
* On button A pressed well use a loop to turn on a random set of LED lights on our micro:bit.
* On button A pressed well use a loop to turn on a random set of LED lights on our micro:bit.
* Our display will have one LED lit for each column or x coordinate value from 0 through 4.
Steps:
* From the Input Toolbox drawer, select the 'on button pressed' block
@ -104,7 +104,7 @@ Steps:
input.onButtonPressed(Button.A, () => {
   basic.clearScreen()
   for (let index = 0; index <= 4; index++) {
       led.plot(index, Math.randomRange(0, 5))
       led.plot(index, randint(0, 5))
   }
})
```
@ -113,8 +113,8 @@ Check the on/off state of an LED
* On button B pressed well use an 'if...then...else' block from the Logic Toolbox drawer
* From the LED Toolbox drawer, drop a 'point x y' block into the 'if' condition to check the current on/off state of a specific LED.
>* If the LED is currently on, the point x y block will return true.
* If the LED is currently off, the point x y block will return false.
>* If the LED is currently on, the point x y block will return true.
* If the LED is currently off, the point x y block will return false.
* For this exercise, well use the two Yes/No built in icons to display the LEDs current status. From the Basic Toolbox drawer, drag 2 'show icon' blocks into each of the 'then' and 'else' clauses. Select the check mark for Yes, and the X icon for No.
* For now, well leave the default coordinate values (0,0). But you can challenge your students to add a loop to test for all coordinates on the micro:bit.
@ -125,7 +125,7 @@ Here is the complete program:
input.onButtonPressed(Button.A, () => {
   basic.clearScreen()
   for (let index = 0; index <= 4; index++) {
       led.plot(index, Math.randomRange(0, 5))
       led.plot(index, randint(0, 5))
   }
})
input.onButtonPressed(Button.B, () => {
@ -203,4 +203,4 @@ basic.showIcon(IconNames.Heart)
### Try it out!
What happens if adding 25 or subtracting 25 from the current brightness level would result in a sum or difference outside of the 0 to 255 brightness range?
What happens if adding 25 or subtracting 25 from the current brightness level would result in a sum or difference outside of the 0 to 255 brightness range?

Просмотреть файл

@ -9,13 +9,13 @@ Normally, if a show was running, or if someone was actively using the computer,
Your task is to create:
* A "screen saver" animation using the plot/unplot blocks. You can fill the screen line by line, pausing between each one, or fill it with a random constellation of stars.
* A "screen saver" animation using the plot/unplot blocks. You can fill the screen line by line, pausing between each one, or fill it with a random constellation of stars.
>-- OR --
* A game that uses sprites to manage the x and y coordinate values of the different objects.
Your project might use variables to store the values of sprites, which are special structures that contain an x and a y coordinate together that describe the sprite's location as one LED on the screen.
Your project might use variables to store the values of sprites, which are special structures that contain an x and a y coordinate together that describe the sprite's location as one LED on the screen.
## Project Ideas
@ -150,7 +150,7 @@ basic.forever(() => {
   } else {
       game.addScore(1)
       ball.set(LedSpriteProperty.Y, 0)
       ball.set(LedSpriteProperty.X, Math.randomRange(0, 5))
       ball.set(LedSpriteProperty.X, randint(0, 5))
   }
})
input.onButtonPressed(Button.A, () => {
@ -163,7 +163,7 @@ input.onButtonPressed(Button.B, () => {
       dodger.change(LedSpriteProperty.X, 1)
   }
})
ball = game.createSprite(Math.randomRange(0, 5), 0)
ball = game.createSprite(randint(0, 5), 0)
dodger = game.createSprite(2, 4)
game.setScore(0)
```
@ -182,7 +182,7 @@ basic.forever(() => {
   } else {
       game.addScore(1)
       ball.set(LedSpriteProperty.Y, 0)
       ball.set(LedSpriteProperty.X, Math.randomRange(0, 5))
       ball.set(LedSpriteProperty.X, randint(0, 5))
   }
})
input.onButtonPressed(Button.A, () => {
@ -195,7 +195,7 @@ input.onButtonPressed(Button.B, () => {
       dodger.change(LedSpriteProperty.X, 1)
   }
})
ball = game.createSprite(Math.randomRange(0, 5), 0)
ball = game.createSprite(randint(0, 5), 0)
dodger = game.createSprite(2, 4)
game.setScore(0)
```
@ -237,6 +237,6 @@ Have students write a reflection of about 150–300 words, addressing the follow
**4 =** Reflection piece addresses all prompts.<br/>
**3 =** Reflection piece lacks 1 of the required elements.<br/>
**2 =** Reflection piece lacks 2 of the required elements.<br/>
**1 =** Reflection piece lacks 3 of the required elements.
**1 =** Reflection piece lacks 3 of the required elements.
 
 

Просмотреть файл

@ -1,6 +1,6 @@
# Crocodile clips
The large holes at the bottom of the board are designed to attach alligator/crocodile clips
The large holes at the bottom of the board are designed to attach alligator/crocodile clips
to create electrical circuit with other components.
# ~hint
@ -22,7 +22,7 @@ Pass one jaw in the hole and grab the side of the board with the other jaw.
For the center holes, ``P1`` and ``P2``, you can also grab the bottom of the board but they are a bit harder to grip.
You can also grip the board between the jaws. In which case, you will want to make sure to avoid overlapping the jaws
You can also grip the board between the jaws. In which case, you will want to make sure to avoid overlapping the jaws
with the other pins as it will create short-circuit in the board.
![](/static/mb/device/croc-clips/badclamp.jpg)
@ -33,13 +33,13 @@ Adding a little tape helps keeping the crocodile clips in place.
## Example: on pin pressed with random numbers
This example displays a random number every time the crocodile clip holds `GND` then connects and disconnects the `P0` pin.
Each time the crocodile clip is firmly connected and disconnected from pin `P0`,
This example displays a random number every time the crocodile clip holds `GND` then connects and disconnects the `P0` pin.
Each time the crocodile clip is firmly connected and disconnected from pin `P0`,
the @boardname@ will return a random Number between 0 and the parameter limit.
```blocks
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(Math.randomRange(0, 10))
basic.showNumber(randint(0, 10))
})
```

Просмотреть файл

@ -73,8 +73,8 @@ basic.forever(() => {
inside = 0
for (let i = 0; i < n; i++) {
// generate a point within the square
x = Math.randomRange(0, r + 1)
y = Math.randomRange(0, r + 1)
x = randint(0, r + 1)
y = randint(0, r + 1)
// test if the point is within the circle
// sqrt(x**2 + y**2) < r ==> x**2 + y**2 < r**2
if (x * x + y * y < r2) {

Просмотреть файл

@ -4,6 +4,6 @@ Generate a random coordinate and display it on the LED screen.
```blocks
basic.forever(() => {
led.toggle(Math.randomRange(0, 4), Math.randomRange(0, 4))
led.toggle(randint(0, 4), randint(0, 4))
})
```

Просмотреть файл

@ -20,29 +20,29 @@ input.onGesture(Gesture.LogoDown, function () {
game.addScore(1);
newAction();
}
})
})
input.onGesture(Gesture.Shake, () => {
if (action == 2) {
game.addScore(1);
newAction();
}
})
})
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score(), 150);
basic.pause(2000);
newAction();
})
})
```
## Challenge 1
Now let's add some more types of instructions for the player to follow. Let's add `"PRESS PIN 0"`.
Change the global variable `action` to `math.randomRange(0, 3)` so that we can add a new **IF** statement that checks if `action == 3`. If it does, display instructions to press pin 0.
Now let's add some more types of instructions for the player to follow. Let's add `"PRESS PIN 0"`.
Change the global variable `action` to `randint(0, 3)` so that we can add a new **IF** statement that checks if `action == 3`. If it does, display instructions to press pin 0.
```typescript
let action = 0;
export function newAction() {
action = Math.randomRange(0, 3)
action = randint(0, 3)
if (action == 0) {
basic.showString("PUSH A", 150) // ***
}

Просмотреть файл

@ -13,13 +13,13 @@ 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
```blocks
let action = Math.randomRange(0, 3)
let action = randint(0, 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.randomRange(0, 3)
let action = randint(0, 3)
if (action == 0) {
basic.showString("PUSH A")
}
@ -29,7 +29,7 @@ if (action == 0) {
```blocks
input.onButtonPressed(Button.A, () => {
let action = Math.randomRange(0, 3)
let action = randint(0, 3)
if (action == 0) {
game.addScore(1)
}
@ -39,7 +39,7 @@ 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.randomRange(0, 3)
let action = randint(0, 3)
if (action == 1) {
basic.showString("LOGO DOWN")
}
@ -49,7 +49,7 @@ if (action == 1) {
```blocks
input.onGesture(Gesture.LogoDown, function () {
let action = Math.randomRange(0, 3)
let action = randint(0, 3)
if (action == 1) {
game.addScore(1)
}
@ -59,7 +59,7 @@ input.onGesture(Gesture.LogoDown, function () {
## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
```blocks
let action = Math.randomRange(0, 3)
let action = randint(0, 3)
if (action == 2) {
basic.showString("SHAKE")
}
@ -69,7 +69,7 @@ if (action == 2) {
```blocks
input.onGesture(Gesture.LogoDown, function () {
let action = Math.randomRange(0, 3)
let action = randint(0, 3)
if (action == 1) {
game.addScore(1)
}

Просмотреть файл

@ -31,7 +31,7 @@ basic.pause(300);
input.acceleration(Dimension.X);
Math.min(0,0);
Math.max(0,1);
Math.randomRange(0, 4);
randint(0, 4);
game.addScore(1);
game.score();
game.removeLife(1);

Просмотреть файл

@ -19,7 +19,7 @@ basic.forever(function() {
led.plot(basketX, 4)
if (eggY > 4) {
eggY = -1
eggX = Math.randomRange(0, 4)
eggX = randint(0, 4)
}
basic.pause(300)
})
@ -50,11 +50,11 @@ basic.forever(function() {
led.plot(basketX1, 4)
if (eggY1 > 4) {
eggY1 = -1
eggX1 = Math.randomRange(0, 4)
eggX1 = randint(0, 4)
}
if (eggY1 == 4) {
if (basketX1 == eggX1) {
game.addScore(1)
game.addScore(1)
} else {
game.removeLife(1)
}
@ -89,7 +89,7 @@ basic.forever(function() {
led.plot(basketX2, 4)
if (eggY2 > 4) {
eggY2 = -1
eggX2 = Math.randomRange(0, 4)
eggX2 = randint(0, 4)
}
if (eggY2 == 4) {
if (basketX2 == eggX2) {
@ -128,7 +128,7 @@ basic.forever(function() {
led.plot(basketX3, 4)
if (eggY3 > 4) {
eggY3 = -1
eggX3 = Math.randomRange(0, 4)
eggX3 = randint(0, 4)
}
if (eggY3 == 4) {
if (basketX3 == eggX3) {
@ -140,7 +140,7 @@ basic.forever(function() {
game.removeLife(1)
}
}
basic.pause(fallingPause1)
basic.pause(fallingPause1)
})
```

Просмотреть файл

@ -24,7 +24,7 @@ basic.forever(function () {
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
if (eggY > 4) {
eggY = -1
eggX = Math.randomRange(0, 4)
eggX = randint(0, 4)
}
led.plot(basketX, 4)
led.plot(basketX, 4)
```

Просмотреть файл

@ -1,6 +1,6 @@
# catch the egg game quiz answers
Programming a game of catch the egg using the accelerometer
Programming a game of catch the egg using the accelerometer
## Name
@ -52,7 +52,7 @@ let eggX = 2
let eggY = 0
if (eggY > 4) {
eggY = -1
eggX = Math.randomRange(0, 5)
eggX = randint(0, 5)
}
```

Просмотреть файл

@ -22,7 +22,7 @@ Learn how to use an if statements to run code run code depending on whether a co
```cards
input.onGesture(Gesture.Shake, () => {})
let x = 0
Math.randomRange(0, 3)
randint(0, 3)
if (true) {}
basic.showLeds(`
. . . . .

Просмотреть файл

@ -13,7 +13,7 @@ Let's create a condition for when the @boardname@ is shaken.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
@ -21,7 +21,7 @@ We need to show a random value from 1 to 6 on our dice. So let's make a local va
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.randomRange(0, 6)
let roll = randint(0, 6)
})
```
@ -30,7 +30,7 @@ We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 be
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.randomRange(0, 6);
let roll = randint(0, 6);
if (roll == 5) {
basic.showLeds(`
. # . # .
@ -48,7 +48,7 @@ Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can s
```blocks
input.onGesture(Gesture.Shake, ()=> {
let roll = Math.randomRange(0, 6);
let roll = randint(0, 6);
if (roll == 5) {
basic.showLeds(`
. # . # .
@ -75,7 +75,7 @@ Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we w
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.randomRange(0, 6);
let roll = randint(0, 6);
if (roll == 5) {
basic.showLeds(`
. # . # .
@ -106,9 +106,9 @@ input.onGesture(Gesture.Shake, () => {
Let's also repeat these steps to show the 3, 2, and 1 on the dice. We are almost done with our dice!
```blocks
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.randomRange(0, 6);
let roll = randint(0, 6);
if (roll == 5) {
basic.showLeds(`
. # . # .

Просмотреть файл

@ -1,14 +1,14 @@
# dice roll challenges
Create a dice on the @boardname@.
Create a dice on the @boardname@.
## Before we get started
Complete the following [guided tutorial](/lessons/dice-roll/activity), your code should look like this:
```blocks
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.randomRange(0, 6);
let roll = randint(0, 6);
if (roll == 5) {
basic.showLeds(`
. # . # .
@ -65,9 +65,9 @@ input.onGesture(Gesture.Shake, () => {
Modify the line of code with `pick random` so that only number 1-4 can appear on the dice.
```blocks
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.randomRange(0, 4);
let roll = randint(0, 4);
if (roll == 5) {
basic.showLeds(`
. # . # .
@ -123,9 +123,9 @@ input.onGesture(Gesture.Shake, () => {
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 @boardname@.
```blocks
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.randomRange(0, 4) + 2;
let roll = randint(0, 4) + 2;
if (roll == 5) {
basic.showLeds(`
. # . # .

Просмотреть файл

@ -1,6 +1,6 @@
# dice roll quiz answers
Create a dice when the @boardname@ is shaken
Create a dice when the @boardname@ is shaken
These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
@ -9,7 +9,7 @@ These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
<br/>
```blocks
let roll = Math.randomRange(0, 6)
let roll = randint(0, 6)
```
## 2. If the variable "roll" equals 5, write the code that will plot the image below
@ -19,7 +19,7 @@ let roll = Math.randomRange(0, 6)
<br/>
```blocks
let roll = Math.randomRange(0, 6)
let roll = randint(0, 6)
if (roll == 5) {
basic.showLeds(`
. # . # .
@ -39,7 +39,7 @@ if (roll == 5) {
```blocks
let roll = Math.randomRange(0, 6)
let roll = randint(0, 6)
if (roll == 5) {
basic.showLeds(`
. # . # .
@ -68,7 +68,7 @@ Note: students are only required to write the bottom half of this answer, starti
<br />
```blocks
let roll = Math.randomRange(0, 6)
let roll = randint(0, 6)
if (roll == 4) {
basic.showLeds(`
. . . . .
@ -97,7 +97,7 @@ Note: students are only required to write the bottom half of this answer, starti
<br />
```blocks
let roll = Math.randomRange(0, 6)
let roll = randint(0, 6)
if (roll == 3) {
basic.showLeds(`
. . . . .

Просмотреть файл

@ -24,7 +24,7 @@ Learn how to create numbers randomly by using the input of the @boardname@. We w
input.onButtonPressed(Button.A, () => {})
let x = 0
basic.showNumber(0)
Math.randomRange(0, 3)
randint(0, 3)
basic.clearScreen()
```

Просмотреть файл

@ -1,6 +1,6 @@
# guess the number activity
Guess the number with math random.
Guess the number with math random.
## ~avatar avatar
@ -21,7 +21,7 @@ Create a local variable of type number `x` and set it to a random number using `
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
})
```
@ -31,7 +31,7 @@ Show the random number on the screen.
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
basic.showNumber(x)
})

Просмотреть файл

@ -1,6 +1,6 @@
# guess the number challenges
Coding challenges for the guess the number tutorial.
Coding challenges for the guess the number tutorial.
## Before we get started
@ -8,7 +8,7 @@ Complete the following [guided tutorial](/lessons/guess-the-number/activity), an
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.randomRange(0, 9)
let x = randint(0, 9)
basic.showNumber(x)
})
```
@ -19,7 +19,7 @@ When button `B` is pressed, we want to clear the screen. This will make it so us
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.randomRange(0, 9)
let x = randint(0, 9)
basic.showNumber(x)
})
input.onButtonPressed(Button.B, () => {

Просмотреть файл

@ -14,7 +14,7 @@ Write the line of code that creates a condition when the @boardname@ button A is
```blocks
input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.A, () => {
})
```
@ -24,14 +24,14 @@ input.onButtonPressed(Button.A, () => {
```blocks
let randomNumber = Math.randomRange(0, 10)
let randomNumber = randint(0, 10)
```
## 4.
## 4.
If the rectangle below represents the @boardname@, shade the areas that will be displayed. Explain why that particular area is shaded.
```blocks
let randomNumber = Math.randomRange(0, 10)
let randomNumber = randint(0, 10)
```

Просмотреть файл

@ -1,4 +1,4 @@
# guess the number quiz
# guess the number quiz
Learn how to generate a random number on the @boardname@.
@ -25,7 +25,7 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
## 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.randomRange(0, 10)
let randomNumber = randint(0, 10)
basic.showNumber(randomNumber)
```

Просмотреть файл

@ -16,7 +16,7 @@ The blocks have been shuffled! Put them back together so that...
```shuffle
input.onButtonPressed(Button.A, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
basic.showNumber(x)
})
```

Просмотреть файл

@ -4,7 +4,7 @@
Your beginning code should look like this:
```blocks
```blocks
let coll: string[] = []
coll.push("puppy")
coll.push("clock")
@ -12,7 +12,7 @@ coll.push("night")
coll.push("cat")
coll.push("cow")
input.onGesture(Gesture.LogoUp, function () {
let index = Math.randomRange(0, coll.length)
let index = randint(0, coll.length)
let word = coll[index]
basic.showString(word)
})
@ -34,7 +34,7 @@ coll.push("night")
coll.push("cat")
coll.push("cow")
input.onGesture(Gesture.LogoUp, function () {
let index = Math.randomRange(0, coll.length)
let index = randint(0, coll.length)
let word = coll[index]
basic.showString(word)
})
@ -42,7 +42,7 @@ input.onGesture(Gesture.ScreenDown, function () {
game.addScore(1)
})
game.startCountdown(60000)
game.startCountdown(60000)
```
* Run your code to see if it works as expected
@ -58,13 +58,13 @@ 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")
coll.push("bicycle")
coll.push("telephone")
coll.push("sun")
coll.push("car")
coll.push("ant")
input.onGesture(Gesture.LogoUp, function () {
let index = Math.randomRange(0, coll.length)
let index = randint(0, coll.length)
let word = coll[index]
basic.showString(word)
})

Просмотреть файл

@ -76,6 +76,6 @@ coll.push("cow")
```blocks
let coll: string[] = []
let index = Math.randomRange(0, coll.length)
let index = randint(0, coll.length)
let word = coll[index]
```

Просмотреть файл

@ -86,7 +86,7 @@ while (true) {
}
else if (false) {
}
}
@ -114,7 +114,7 @@ while (true) {
else if (ghost.get(LedSpriteProperty.Y) > hero.get(LedSpriteProperty.Y)) {
ghost.change(LedSpriteProperty.Y, -1 );
}
}
@ -193,8 +193,8 @@ while (true) {
}
if (hero.isTouching(food)) {
game.addScore(1);
food.set(LedSpriteProperty.X, Math.randomRange(0, 5));
food.set(LedSpriteProperty.Y, Math.randomRange(0, 5));
food.set(LedSpriteProperty.X, randint(0, 5));
food.set(LedSpriteProperty.Y, randint(0, 5));
}
}
@ -241,8 +241,8 @@ while (true) {
}
if (hero.isTouching(food)) {
game.addScore(1);
food.set(LedSpriteProperty.X, Math.randomRange(0, 5));
food.set(LedSpriteProperty.Y, Math.randomRange(0, 5));
food.set(LedSpriteProperty.X, randint(0, 5));
food.set(LedSpriteProperty.Y, randint(0, 5));
if (food.get(LedSpriteProperty.X) < 2 && food.get(LedSpriteProperty.Y) < 2) {
ghost.set(LedSpriteProperty.X, 4);
ghost.set(LedSpriteProperty.Y, 4);

Просмотреть файл

@ -24,7 +24,7 @@ Learn how to use the **pin pressed**, `on pin pressed` to run code when the user
if (true) {}
input.onPinPressed(TouchPin.P0, () => {})
let x = 0
Math.randomRange(0, 3)
randint(0, 3)
basic.showNumber(0)
basic.pause(100)
```

Просмотреть файл

@ -13,7 +13,7 @@ Begin by registering an event with `on pin pressed` *P0* to know when someone is
```blocks
input.onPinPressed(TouchPin.P0, () => {
})
```
@ -23,7 +23,7 @@ We are going to create a meter that displays a random number from *0* to *10*. W
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
})
```
@ -33,7 +33,7 @@ Finally, let's show that number on the @boardname@. You are registering an event
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
basic.showNumber(x)
})

Просмотреть файл

@ -1,6 +1,6 @@
# love meter blocks challenges
Create a love meter with the @boardname@
Create a love meter with the @boardname@
## Before we get started
@ -8,7 +8,7 @@ You should work on these challenges after the following the [love meter activity
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
basic.showNumber(x)
})
@ -21,7 +21,7 @@ Add a pause of 3000 milliseconds (3 seconds) after showing the number so that th
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
basic.showNumber(x)
basic.pause(3000)
})
@ -34,7 +34,7 @@ If the rating **x** is between *0* and *3* (strictly less than *4*), display the
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
basic.showNumber(x)
basic.pause(3000)
if (x < 4) {
@ -49,7 +49,7 @@ input.onPinPressed(TouchPin.P0, () => {
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.randomRange(0, 10)
let x = randint(0, 10)
basic.showNumber(x)
basic.pause(3000)
if (x < 4) {

Просмотреть файл

@ -1,6 +1,6 @@
# love meter blocks quiz answers
The answers to the love meter quiz.
The answers to the love meter quiz.
This is the answer key for the [love meter quiz](/lessons/love-meter/quiz).
@ -16,14 +16,14 @@ Create a condition for `on pin pressed (P0)`.
```blocks
input.onPinPressed(TouchPin.P0, () => {
})
```
## 3. What does this line of code doing?
```blocks
let x = Math.randomRange(0, 9)
let x = randint(0, 9)
```

Просмотреть файл

@ -1,6 +1,6 @@
# love meter blocks quiz
# love meter blocks quiz
Learn how to make a love meter that you can try with someone.
Learn how to make a love meter that you can try with someone.
## Name
@ -19,7 +19,7 @@ Answer the questions below while completing the activity. Pay attention to the d
## 3. Describe what this line of code does?
```blocks
let x = Math.randomRange(0, 9)
let x = randint(0, 9)
```

Просмотреть файл

@ -22,7 +22,7 @@ Learn how to creating **conditionals**, `if condition do` to conditionally run c
```cards
if (true) {}
Math.randomRange(0, 3)
randint(0, 3)
input.onGesture(Gesture.Shake, () => {})
basic.showNumber(7)
basic.clearScreen()

Просмотреть файл

@ -34,7 +34,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 3)
let randomNumber = randint(0, 3)
});
```
@ -47,7 +47,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen();
let randomNumber = Math.randomRange(0, 3);
let randomNumber = randint(0, 3);
if (randomNumber == 2) {
basic.showString("YES");
}
@ -63,7 +63,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 3)
let randomNumber = randint(0, 3)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
@ -79,7 +79,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 3)
let randomNumber = randint(0, 3)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
@ -101,7 +101,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 3)
let randomNumber = randint(0, 3)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {

Просмотреть файл

@ -1,6 +1,6 @@
# magic 8 challenges
Coding challenges for the magic 8 tutorial
Coding challenges for the magic 8 tutorial
## Before we get started
@ -11,7 +11,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 2)
let randomNumber = randint(0, 2)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
@ -35,7 +35,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 4)
let randomNumber = randint(0, 4)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
@ -59,7 +59,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 4)
let randomNumber = randint(0, 4)
if (randomNumber == 3) {
basic.showString("TRY AGAIN")
} else if (randomNumber == 2) {
@ -82,7 +82,7 @@ basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.randomRange(0, 4)
let randomNumber = randint(0, 4)
if (randomNumber == 4) {
basic.showString("DEFINATELY")
} else if (randomNumber == 3) {

Просмотреть файл

@ -19,13 +19,13 @@ An if statement will conditionally run code depending on whether or not a condit
## 2. Create a Variable called ``x`` and assign it to a random number between 0 and 2.
```blocks
let x = Math.randomRange(0, 3)
let x = randint(0, 3)
```
## 3. Write the 'if statement' to check if ``x`` is equal to 2. Inside the 'if statement', display the string "Yes".
```blocks
let x = Math.randomRange(0, 3)
let x = randint(0, 3)
if (x == 2) {
basic.showString("Yes", 150)
}
@ -34,7 +34,7 @@ if (x == 2) {
## 4. Write the 'if statement' to check if ``x`` is equal to 1. Inside the 'if statement', display the string "No."
```blocks
let x = Math.randomRange(0, 3)
let x = randint(0, 3)
if (x == 2) {
basic.showString("Yes", 150)
} else if (x == 1) {
@ -45,7 +45,7 @@ if (x == 2) {
## 5. Write the code to display the string "I don't know" if the Variable ``x`` is neither 2 nor 1.
```blocks
let x = Math.randomRange(0, 3)
let x = randint(0, 3)
if (x == 2) {
basic.showString("Yes", 150)
} else if (x == 1) {

Просмотреть файл

@ -15,7 +15,7 @@ The blocks have been shuffled! Put them back together so that...
```shuffle
basic.showString("ASK A QUESTION")
input.onGesture(Gesture.Shake, () => {
let randomNumber = Math.randomRange(0, 3)
let randomNumber = randint(0, 3)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {

Просмотреть файл

@ -25,7 +25,7 @@ Learn how to use an if statement to run code run code depending on whether a con
if (true) {}
let x = 0
input.onGesture(Gesture.Shake, () => {})
Math.randomRange(0, 3)
randint(0, 3)
basic.showLeds(`
. . . . .
. . . . .

Просмотреть файл

@ -1,6 +1,6 @@
# spinner activity
Create an arrow that randomly points to a player.
Create an arrow that randomly points to a player.
## ~avatar avatar
@ -14,7 +14,7 @@ Let's begin by adding an `on shake` condition to know when the @boardname@ is sh
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
@ -22,7 +22,7 @@ Now let's randomly generate a number from 0 to 3 so that we can randomly display
```blocks
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.randomRange(0, 4)
let randomArrow = randint(0, 4)
if (randomArrow == 3) {
basic.showLeds(`
. . # . .
@ -41,7 +41,7 @@ Now let's handle each of the cases by displaying the appropriate arrow. (Let's d
```blocks
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.randomRange(0, 4)
let randomArrow = randint(0, 4)
if (randomArrow == 3) {
basic.showLeds(`
. . # . .
@ -69,7 +69,7 @@ Now let's handle the rest of the cases for `random arrow`.
```blocks
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.randomRange(0, 4)
let randomArrow = randint(0, 4)
if (randomArrow == 3) {
basic.showLeds(`
. . # . .

Просмотреть файл

@ -8,7 +8,7 @@ Complete the following [guided tutorial](/lessons/spinner/activity), your code s
```blocks
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.randomRange(0, 4)
let randomArrow = randint(0, 4)
if (randomArrow == 3) {
basic.showLeds(`
. . # . .
@ -46,7 +46,7 @@ Modify the random number generator so that it can include new arrows we will cre
```blocks
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.randomRange(0, 8)
let randomArrow = randint(0, 8)
if (randomArrow == 3) {
basic.showLeds(`
. . # . .
@ -89,7 +89,7 @@ Let's add more arrows that point diagonally.
```blocks
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.randomRange(0, 8)
let randomArrow = randint(0, 8)
if (randomArrow == 7) {
basic.showLeds(`
. . # . .

Просмотреть файл

@ -15,17 +15,17 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
<br/>
```blocks
let randomArrow = Math.randomRange(0, 4)
let randomArrow = randint(0, 4)
```
## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1.
## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1.
![](/static/mb/lessons/spinner-0.png)
<br/>
```blocks
let randomArrow = Math.randomRange(0, 4);
let randomArrow = randint(0, 4);
if (randomArrow == 1) {
basic.showLeds(`
. . # . .
@ -37,14 +37,14 @@ if (randomArrow == 1) {
}
```
## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2.
## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2.
![](/static/mb/lessons/spinner-1.png)
<br />
```blocks
let randomArrow = Math.randomRange(0, 4);
let randomArrow = randint(0, 4);
if (randomArrow == 2) {
basic.showLeds(`
. . # . .

Просмотреть файл

@ -32,7 +32,7 @@ basic.showLeds(`
`)
input.onButtonPressed(Button.A, () => {})
let x = 0
Math.randomRange(0, 3)
randint(0, 3)
if (true) {}
basic.showString("Hello!")
```

Просмотреть файл

@ -1,6 +1,6 @@
# truth or dare activity
A multi-player game that forces each player to reveal a secret or something funny.
A multi-player game that forces each player to reveal a secret or something funny.
## ~avatar avatar
@ -34,7 +34,7 @@ basic.showLeds(`
. . # . .
`)
input.onButtonPressed(Button.A, () => {
let random = Math.randomRange(0, 2)
let random = randint(0, 2)
})
```
@ -49,7 +49,7 @@ basic.showLeds(`
. . # . .
`)
input.onButtonPressed(Button.A, () => {
let random = Math.randomRange(0, 2)
let random = randint(0, 2)
if (random == 0) {
basic.showString("TRUTH")
} else {
@ -71,7 +71,7 @@ basic.showLeds(`
. . # . .
`)
input.onButtonPressed(Button.A, () => {
let random = Math.randomRange(0, 2)
let random = randint(0, 2)
if (random == 0) {
basic.showString("TRUTH")
} else {

Просмотреть файл

@ -1,6 +1,6 @@
# truth or dare challenges
A multi-player game that forces each player to reveal a secret or something funny.
A multi-player game that forces each player to reveal a secret or something funny.
## Before we get started
@ -16,7 +16,7 @@ basic.showLeds(`
. . # . .
`)
input.onButtonPressed(Button.A, () => {
let random = Math.randomRange(0, 2)
let random = randint(0, 2)
if (random == 0) {
basic.showString("TRUTH")
} else {
@ -45,7 +45,7 @@ basic.showLeds(`
. . # . .
`)
input.onButtonPressed(Button.A, () => {
let random = Math.randomRange(0, 3)
let random = randint(0, 3)
if (random == 0) {
basic.showString("TRUTH")
} else {
@ -75,7 +75,7 @@ basic.showLeds(`
. . # . .
`)
input.onButtonPressed(Button.A, () => {
let random = Math.randomRange(0, 2)
let random = randint(0, 2)
if (random == 1) {
basic.showString("TRUTH")
} else if (random == 0) {

Просмотреть файл

@ -7,19 +7,19 @@ This is the answer key for the [truth or dare quiz](/lessons/truth-or-dare/quiz)
## 1. Write the code that will randomly return 0 through 3 and stores the value inside a local variable called 'random'.
```blocks
let random = Math.randomRange(0, 4)
let random = randint(0, 4)
```
## 2. Write an if statement that will display the message "TRUTH" on the @boardname@ if the local variable 'random' equals 0.
## 2. Write an if statement that will display the message "TRUTH" on the @boardname@ if the local variable 'random' equals 0.
```blocks
let random = Math.randomRange(0, 4)
let random = randint(0, 4)
if (random == 0) {
basic.showString("TRUTH", 150)
}
```
## 3. If the local variable 'random' equals 1, write the string that will be displayed.
## 3. If the local variable 'random' equals 1, write the string that will be displayed.
DARE

Просмотреть файл

@ -4,8 +4,8 @@
The *Truth or dare!* game works as follows: a player spins the @boardname@ on the table.
When the @boardname@ stops spinning, the player pointed by the arrow (displayed on screen) must press the button "A"
The *Truth or dare!* game works as follows: a player spins the @boardname@ on the table.
When the @boardname@ stops spinning, the player pointed by the arrow (displayed on screen) must press the button "A"
to see if she has to provide a *truth* or a *dare*.
## ~
@ -27,7 +27,7 @@ basic.showLeds(`
. . # . .
`)
input.onButtonPressed(Button.A, () => {
let random = Math.randomRange(0, 2)
let random = randint(0, 2)
if (random == 0) {
basic.showString("TRUTH")
} else {
@ -53,7 +53,7 @@ basic.showLeds(`
. . # . .
. . # . .
`);
Math.randomRange(0, 2);
randint(0, 2);
basic.showString("TRUTH");
if (true) {} else {}
"TRUTH";

Просмотреть файл

@ -1,4 +1,4 @@
# Crashy Bird
# Crashy Bird
## ~avatar avatar
@ -10,7 +10,7 @@ This is a simple version of the Flappy Bird game for @boardname@. The objective
## Step 1: Add the Bird to the Game
First, we are going to add a sprite for the bird from the **Game** menu and make it blink.
First, we are going to add a sprite for the bird from the **Game** menu and make it blink.
```blocks
let bird: game.LedSprite = null
@ -20,7 +20,7 @@ bird.set(LedSpriteProperty.Blink, 300)
## Step 2: Make the Bird fly
Before creating the code for the game actions, let's first add some controls so that we can move around. We'll control the bird by pressing the **A** button to go up or the **B** button to go down.
Before creating the code for the game actions, let's first add some controls so that we can move around. We'll control the bird by pressing the **A** button to go up or the **B** button to go down.
```blocks
let bird: game.LedSprite = null
@ -35,16 +35,16 @@ input.onButtonPressed(Button.B, () => {
## Step 3: Generating obstacles
This is where things will start to get interesting. We're going to randomly generate obstacles. We'll keep all obstacles inside the array. All obstacles will have a single hole for the bird to fly through.
This is where things will start to get interesting. We're going to randomly generate obstacles. We'll keep all obstacles inside the array. All obstacles will have a single hole for the bird to fly through.
First, create an array of `obstacles` which will hold all of the obstacle sprites.
First, create an array of `obstacles` which will hold all of the obstacle sprites.
```blocks
let obstacles: game.LedSprite[] = []
```
Now generate vertical obstacles consisting of 4 sprites and 1 random hole.
Create new variable called `emptyObstacleY`. Using ``||math:pick random||``, generate a random number from `0` to `4` and store it inside `emptyObstacleY`.
Now generate vertical obstacles consisting of 4 sprites and 1 random hole.
Create new variable called `emptyObstacleY`. Using ``||math:pick random||``, generate a random number from `0` to `4` and store it inside `emptyObstacleY`.
Using ``||loops:for||`` loop, iterate from `0` to `4`. For every coordinate not equal to `emptyObstacleY` create and add obstacle sprites to the end of the `obstacles` array.
@ -52,15 +52,15 @@ Using ``||loops:for||`` loop, iterate from `0` to `4`. For every coordinate not
let emptyObstacleY = 0
let obstacles: game.LedSprite[] = []
emptyObstacleY = Math.randomRange(0, 4)
emptyObstacleY = randint(0, 4)
for (let index = 0; index <= 4; index++) {
if (index != emptyObstacleY) {
obstacles.push(game.createSprite(4, index))
}
}
```
```
Now with every @boardname@ restart you should see different autogenerated vertical obstacles.
Now with every @boardname@ restart you should see different autogenerated vertical obstacles.
Before continuing, make sure that obstacles are generated randomly and that the bird is moving up and down.
@ -72,7 +72,7 @@ let bird: game.LedSprite = null
bird = game.createSprite(0, 2)
bird.set(LedSpriteProperty.Blink, 300)
emptyObstacleY = Math.randomRange(0, 4)
emptyObstacleY = randint(0, 4)
for (let index = 0; index <= 4; index++) {
if (index != emptyObstacleY) {
obstacles.push(game.createSprite(4, index))
@ -90,7 +90,7 @@ input.onButtonPressed(Button.B, () => {
## Step 4: Make obstacles move
Access each obstacle using a ``||for element||`` loop (_iterate_ over the `obstacles` array) and decrease the `obstacle` `X` coordinate by 1.
Access each obstacle using a ``||for element||`` loop (_iterate_ over the `obstacles` array) and decrease the `obstacle` `X` coordinate by 1.
Right click on the ``||value||`` block and rename it to ``||obstacle||``
; then drag that ``||obstacle||`` block on top of ``||sprite||`` in the ``||game:change x||`` block.
@ -105,11 +105,11 @@ basic.forever(() => {
})
```
Obstacles should move towards left every second.
Obstacles should move towards left every second.
## Step 5: Make obstacles disappear
Make obstacles disappear after reaching leftmost corner. Iterate over all obstacles, delete the obstacle sprites where the `X` coordinate equals `0`, and remove them from the ``obstacles`` array.
Make obstacles disappear after reaching leftmost corner. Iterate over all obstacles, delete the obstacle sprites where the `X` coordinate equals `0`, and remove them from the ``obstacles`` array.
```blocks
let obstacles: game.LedSprite[] = []
@ -142,7 +142,7 @@ basic.forever(() => {
for (let obstacle of obstacles) {
obstacle.change(LedSpriteProperty.X, -1)
}
emptyObstacleY = Math.randomRange(0, 4)
emptyObstacleY = randint(0, 4)
for (let index = 0; index <= 4; index++) {
if (index != emptyObstacleY) {
obstacles.push(game.createSprite(4, index))
@ -152,7 +152,7 @@ basic.forever(() => {
})
```
Now our screen is full of moving obstacles. Create some spaces between generated obstacles. Let's introduce a `ticks` variable to count how many iterations the ``||basic:forever||`` loop has done and execute obstacle creation only if `ticks` is divisible by 3.
Now our screen is full of moving obstacles. Create some spaces between generated obstacles. Let's introduce a `ticks` variable to count how many iterations the ``||basic:forever||`` loop has done and execute obstacle creation only if `ticks` is divisible by 3.
```blocks
let ticks = 0
@ -168,7 +168,7 @@ basic.forever(() => {
obstacle.change(LedSpriteProperty.X, -1)
}
if (ticks % 3 == 0) {
emptyObstacleY = Math.randomRange(0, 4)
emptyObstacleY = randint(0, 4)
for (let index = 0; index <= 4; index++) {
if (index != emptyObstacleY) {
obstacles.push(game.createSprite(4, index))
@ -182,7 +182,7 @@ basic.forever(() => {
## Step 7: Game Over
Right now nothing happens when the bird is hit by obstacle. Fix this by iterating over the `obstacles` array and checking if any obstacle sprite coordinate equals the bird coordinate.
Right now nothing happens when the bird is hit by obstacle. Fix this by iterating over the `obstacles` array and checking if any obstacle sprite coordinate equals the bird coordinate.
```blocks
let bird: game.LedSprite = null
@ -199,7 +199,7 @@ basic.forever(() => {
obstacle.change(LedSpriteProperty.X, -1)
}
if (ticks % 3 == 0) {
emptyObstacleY = Math.randomRange(0, 4)
emptyObstacleY = randint(0, 4)
for (let index = 0; index <= 4; index++) {
if (index != emptyObstacleY) {
obstacles.push(game.createSprite(4, index))
@ -244,7 +244,7 @@ basic.forever(() => {
obstacle2.change(LedSpriteProperty.X, -1)
}
if (ticks % 3 == 0) {
emptyObstacleY = Math.randomRange(0, 4)
emptyObstacleY = randint(0, 4)
for (let index2 = 0; index2 <= 4; index2++) {
if (index2 != emptyObstacleY) {
obstacles.push(game.createSprite(4, index2))

Просмотреть файл

@ -35,7 +35,7 @@ Put a ``||Math:pick random||`` block in the ``||basic:show number||`` block to p
```blocks
input.onGesture(Gesture.Shake, () => {
basic.showNumber(Math.randomRange(0, 10))
basic.showNumber(randint(0, 10))
})
```
@ -45,7 +45,7 @@ A typical dice shows values from `1` to `6`. So, in ``||Math:pick random||``, do
```blocks
input.onGesture(Gesture.Shake, () => {
basic.showNumber(Math.randomRange(1, 6))
basic.showNumber(randint(1, 6))
})
```

Просмотреть файл

@ -35,7 +35,7 @@ input.onGesture(Gesture.LogoUp, function () {
## Step 4
The items in ``||arrays:text list||`` are numbered ``0`` to ``length - 1``.
The items in ``||arrays:text list||`` are numbered ``0`` to ``length - 1``.
Add code to pick a ``||math:random||`` ``||variables:index||``.
```blocks
@ -43,7 +43,7 @@ let text_list: string[] = []
let index = 0
input.onGesture(Gesture.LogoUp, function () {
// @highlight
index = Math.randomRange(0, text_list.length - 1)
index = randint(0, text_list.length - 1)
})
```
@ -55,7 +55,7 @@ Add code to ``||basic:show||`` the value of the item stored at ``||variables:ind
let text_list: string[] = []
let index = 0
input.onGesture(Gesture.LogoUp, function () {
index = Math.randomRange(0, text_list.length - 1)
index = randint(0, text_list.length - 1)
// @highlight
basic.showString(text_list[index])
})

Просмотреть файл

@ -16,7 +16,7 @@ input.onButtonPressed(Button.A, function () {
## Step 2
Make a ``||variables:timer||`` variable and ``||variables:set||`` it to
Make a ``||variables:timer||`` variable and ``||variables:set||`` it to
a ``||math:random value||`` between ``5`` and ``15``.
The value of ``||variables:timer||`` represents the number of seconds left before someone is caught holding the potato.
@ -25,7 +25,7 @@ The value of ``||variables:timer||`` represents the number of seconds left befor
let timer = 0
input.onButtonPressed(Button.A, function () {
// @highlight
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
})
```
@ -36,7 +36,7 @@ Add code to ``||basic:show||`` that the game started.
```blocks
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
// @highlight
basic.showIcon(IconNames.Chessboard)
})
@ -50,7 +50,7 @@ Put in a loop to repeat code ``||loops:while||`` ``||variables:timer||`` ``||lo
```blocks
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
basic.showIcon(IconNames.Chessboard)
// @highlight
while (timer > 0) {
@ -65,7 +65,7 @@ Inside the ``||loops:while||`` loop, add code to ``||variables:decrease||`` the
```blocks
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
basic.showIcon(IconNames.Chessboard)
while (timer > 0) {
// @highlight
@ -83,7 +83,7 @@ input.onButtonPressed(Button.A, function () {
```blocks
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
basic.showIcon(IconNames.Chessboard)
while (timer > 0) {
timer += -1

Просмотреть файл

@ -6,7 +6,7 @@ There is a disease outbreak! Will you find patient zero?!?
## ~
**Infection** is a distributed game which simulates
**Infection** is a distributed game which simulates
the spread of an illness. **The goal is to stop the outbreak before every player dies!**
* **Number of players:** 1 Master and 4, or more, additional players. The Master and all other players need a @boardname@ with battery pack.
@ -32,16 +32,16 @@ Press `A+B` to enter Master mode (there's only one Master in a game).
Wait for players to be paired. The number of paired players will display on the screen.
When paired, a letter appears on the player's screen, this letter is the player's identity.
Once all of your players are registered, press `A+B` to start the infection game.
Once all of your players are registered, press `A+B` to start the infection game.
The game randomly picks a player as **patient zero**.
A player will transmit the disease to another player if close enough (detecting a sufficient `RSSI`), and if a certain probability (`TRANSMISSIONPROB`) of disease transfer is reached.
During the incubation phase (`INCUBATION`), the player does not show any sign of illness (happy face).
A player will transmit the disease to another player if close enough (detecting a sufficient `RSSI`), and if a certain probability (`TRANSMISSIONPROB`) of disease transfer is reached.
During the incubation phase (`INCUBATION`), the player does not show any sign of illness (happy face).
After that phase, the player gets sick and shows a sad face on the screen. After the sick (sad) face, the player dies and a skull shows up.
Once the game is over, the @boardname@ will show the player's id (`A`, `B`, `C`...), health, and
Once the game is over, the @boardname@ will show the player's id (`A`, `B`, `C`...), health, and
the id of the player who infected them. The Master @boardname@ will show the identity of patient zero.
Icons used in the game:
* Pairing: `IconNames.Ghost`
@ -74,37 +74,37 @@ As a result, it will not convert back to blocks.
```typescript
/**
* Infection game
*
*
* Flash all micro:bits with this script
*
*
* Press A+B to enter master mode (1 per game)
*
* Wait for players to be paired. The number of paired player will display on screen.
* An icon will appear on player's screen.
*
*
* Press A+B to start the infection game. The master will pick a random
* player as patient zero.
*
* A player will transmit the disease if close enough (RSSI)
* and with a certain probability (TRANSMISSIONPROB).
* During the incudation phase (INCUBATION), the player does not show any sign
* and with a certain probability (TRANSMISSIONPROB).
* During the incudation phase (INCUBATION), the player does not show any sign
* of illness. After that phase, the sad face shows up.
*
*
* The game will automatically stop once all players are dead or healthy. The master can
* also press A+B again to stop the game.
*
* Once the game is over, the micro:bit will show the player id (A,B,C...), health and
*
* Once the game is over, the micro:bit will show the player id (A,B,C...), health and
* who infected him.
*
*
* Icons used in the game:
*
*
* Pairing: IconNames.Ghost
* Paired: IconNames.Happy
* Dead: IconNames.Skull
* Sick: IconNames.Sad
* Incubating: IconNames.Confused
* Healthy: IconNames.Happy
*
*
*/
const INCUBATION = 20000; // time before showing symptoms
const DEATH = 40000; // time before dying off the disease
@ -322,12 +322,12 @@ input.onButtonPressed(Button.AB, () => {
// launch game
if (state == GameState.Pairing) {
// pick 1 player and infect him
patientZero = players[Math.randomRange(0, players.length - 1)];
// infecting message needs to be confirmed by
patientZero = players[randint(0, players.length - 1)];
// infecting message needs to be confirmed by
// the player
state = GameState.Infecting;
serial.writeLine(`game started ${players.length} players`);
} // end game
} // end game
else if (state == GameState.Running) {
gameOver();
}
@ -394,7 +394,7 @@ radio.onReceivedBuffer(function (receivedBuffer: Buffer) {
if (health == HealthState.Healthy) {
serial.writeLine(`signal: ${signal}`);
if (signal > RSSI &&
Math.randomRange(0, 100) > TRANSMISSIONPROB) {
randint(0, 100) > TRANSMISSIONPROB) {
infectedBy = incomingMessage.value;
infectedTime = input.runningTime();
health = HealthState.Incubating;

Просмотреть файл

@ -21,7 +21,7 @@ Using ``||basic:show number||`` and ``||Math:pick random||`` blocks, show a rand
```blocks
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(Math.randomRange(0, 100));
basic.showNumber(randint(0, 100));
});
```
## Step 3
@ -35,7 +35,7 @@ Show ``"LOVE METER"`` on the screen when the @boardname@ starts.
```blocks
basic.showString("LOVE METER");
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(Math.randomRange(0, 100));
basic.showNumber(randint(0, 100));
});
```

Просмотреть файл

@ -2,12 +2,13 @@
## ~ avatar
Have you heard about BitCoin and all those new Crypto currencies? Well micro:bit has **micro:coin** now!
Have you heard about BitCoin and all those new Crypto currencies? Well micro:bit has **micro:coin** now!
## ~
## How does a @boardname@ make coins?
Each @boardname@ contains a **blockchain**, a sequence of **blocks**, that is public and can't be modified. Each block represents a **coin**. To mine new coins, the user shakes
the @boardname@ and, if they are in luck, their coin added to the chain as a new block!
Once the block is added, it is broadcasted to the other @boardname@ (the block chain is public and can't be modified so it's ok to share it). Other @boardname@s receive the block, validate the transaction and update their block chain as needed.
@ -42,7 +43,7 @@ input.onGesture(Gesture.Shake, () => {
led.stopAnimation()
basic.clearScreen()
basic.pause(200) // display a short pause
if (Math.randomRange(0, 2) == 0) { // 30% chances to add a transaction
if (randint(0, 2) == 0) { // 30% chances to add a transaction
// we found a coin!!!
blockchain.addBlock(1);
basic.showIcon(IconNames.Diamond);

Просмотреть файл

@ -14,7 +14,7 @@ Let's start by rebuilding the **dice** game. If you are unsure about the details
```blocks
input.onGesture(Gesture.Shake, function () {
basic.showNumber(Math.randomRange(1, 6))
basic.showNumber(randint(1, 6))
})
```
@ -22,14 +22,14 @@ input.onGesture(Gesture.Shake, function () {
We need to store the result of the dice cast in a variable. A **variable** is like a place in the memory of the @boardname@ where you save information, like numbers.
* Go to the **Variables** toolbox and click ``||Make a Variable||`` to create a new variable. We will call it **dice**.
* Go to the **Variables** toolbox and click ``||Make a Variable||`` to create a new variable. We will call it **dice**.
* Add a ``||set dice to||`` block and drag the ``||pick random||`` into it.
* Drag a ``||dice||`` from the **Variables** toolbox into the ``||basic:show number||`` block.
```blocks
let dice = 0
input.onGesture(Gesture.Shake, function () {
dice = Math.randomRange(1, 6)
dice = randint(1, 6)
basic.showNumber(dice)
})
```
@ -41,7 +41,7 @@ Put in a ``||radio:send number||`` and a ``||dice||`` to send the value stored i
```blocks
let dice = 0
input.onGesture(Gesture.Shake, function () {
dice = Math.randomRange(1, 6)
dice = randint(1, 6)
basic.showNumber(dice)
radio.sendNumber(dice)
})
@ -58,7 +58,7 @@ radio.onReceivedNumber(function (receivedNumber) {
## Check your cast
Add a ``||logic:if||`` block to test if ``receivedNumber`` is greater or equal to ``dice``.
Add a ``||logic:if||`` block to test if ``receivedNumber`` is greater or equal to ``dice``.
If is, you lost so display a sad face on the screen.
```blocks
@ -79,7 +79,7 @@ If you have more than one @boardname@, download your code onto each one and try
```blocks
let dice = 0
input.onGesture(Gesture.Shake, function () {
dice = Math.randomRange(1, 6)
dice = randint(1, 6)
basic.showNumber(dice)
radio.sendNumber(dice)
})

Просмотреть файл

@ -13,7 +13,7 @@ let group = 0
*/
radio.onReceivedNumber(function (receivedNumber) {
radio.writeReceivedPacketToSerial()
led.toggle(Math.randomRange(0, 4), Math.randomRange(0, 4))
led.toggle(randint(0, 4), randint(0, 4))
})
/**
* Decrement radio group by 1

Просмотреть файл

@ -4,7 +4,7 @@
This lesson uses the @boardname@ to measure a student's reaction time in completing a circuit path on a cardboard pad. The student's reaction time is measured in both a distracted and an undistracted environment.
Connect each piece of foil to the appropriate pin on the @boardname@.
Connect each piece of foil to the appropriate pin on the @boardname@.
**Note:** For the experiment we are **not** using the **P2** pin as shown in the video.
@ -20,7 +20,7 @@ In order for **Reaction Time** to track the speed of a a player's reaction, we n
So, our tracking variables do this:
- the reaction time experiment starts and ends at specific times based on the player's reaction.
- the code tracks when the experiment is running as well as when the player has a false start.
- the code tracks when the experiment is running as well as when the player has a false start.
Add these variables to your code:
@ -47,10 +47,10 @@ let end = 0
let false_start = false
let running = false
input.onPinPressed(TouchPin.P0, () => {
})
input.onPinPressed(TouchPin.P1, () => {
})
running = false
false_start = false
@ -74,7 +74,7 @@ input.onPinPressed(TouchPin.P0, () => {
basic.clearScreen()
})
input.onPinPressed(TouchPin.P1, () => {
})
running = false
false_start = false
@ -82,7 +82,7 @@ end = 0
start = 0
```
## Step 4: Boolean
## Step 4: Boolean
Now we'll set the variables `running` and `false_start` to `false` in the **P0** event.
@ -102,7 +102,7 @@ input.onPinPressed(TouchPin.P0, () => {
false_start = false
})
input.onPinPressed(TouchPin.P1, () => {
})
running = false
false_start = false
@ -110,7 +110,7 @@ end = 0
start = 0
```
## Step 5: Begin reaction time randomly
## Step 5: Begin reaction time randomly
Let's add a random starting time after pin **p0** is pressed. Include the ``||math:random||`` block in a ``||basic:pause||`` at the bottom of the event block like this:
@ -126,10 +126,10 @@ input.onPinPressed(TouchPin.P0, () => {
basic.clearScreen()
running = false
false_start = false
basic.pause(1000 + Math.randomRange(0, 2000))
basic.pause(1000 + randint(0, 2000))
})
input.onPinPressed(TouchPin.P1, () => {
})
running = false
false_start = false
@ -137,7 +137,7 @@ end = 0
start = 0
```
## Step 6: Plot LED on X, Y coordinates randomly
## Step 6: Plot LED on X, Y coordinates randomly
The reaction time will begin if no false start is detected (pin **P0** pressed at the wrong time). When the reaction time starts, a LED is randomly plotted at some the x and y coordinate on the display. Add in the blocks contained in the ``||logic:if then||`` that show the reaction time:
@ -147,7 +147,7 @@ let end = 0
let false_start = false
let running = false
input.onPinPressed(TouchPin.P1, () => {
})
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(3)
@ -156,13 +156,13 @@ input.onPinPressed(TouchPin.P0, () => {
basic.clearScreen()
running = false
false_start = false
basic.pause(1000 + Math.randomRange(0, 2000))
basic.pause(1000 + randint(0, 2000))
if (!(false_start)) {
start = input.runningTime()
running = true
led.stopAnimation()
basic.clearScreen()
led.plot(Math.randomRange(0, 4), Math.randomRange(0, 4))
led.plot(randint(0, 4), randint(0, 4))
}
})
running = false
@ -171,9 +171,9 @@ end = 0
start = 0
```
## Step 7: Display feedback to reaction
## Step 7: Display feedback to reaction
Add some code to detect when the player presses the **GND** foil with one hand and the **P1** pin with the other. This code detects the circuit connection and shuts off the timer. Also, add code to have the @boardname@ read the time in milliseconds from when the timer starts and the circuit is completed. This code also detects if there is a correct reaction or false start if pin **P1** is pressed.
Add some code to detect when the player presses the **GND** foil with one hand and the **P1** pin with the other. This code detects the circuit connection and shuts off the timer. Also, add code to have the @boardname@ read the time in milliseconds from when the timer starts and the circuit is completed. This code also detects if there is a correct reaction or false start if pin **P1** is pressed.
Let's display one of two images if pin **P1** is pressed. The first image displays if the player correctly completes the circuit between **GND** and **P1**. This means that a correct reaction occurred to complete the circuit with pin **P1** pressed after the randomly generated LED appears.
@ -215,13 +215,13 @@ input.onPinPressed(TouchPin.P0, () => {
basic.clearScreen()
running = false
false_start = false
basic.pause(1000 + Math.randomRange(0, 2000))
basic.pause(1000 + randint(0, 2000))
if (!(false_start)) {
start = input.runningTime()
running = true
led.stopAnimation()
basic.clearScreen()
led.plot(Math.randomRange(0, 4), Math.randomRange(0, 4))
led.plot(randint(0, 4), randint(0, 4))
}
})
running = false
@ -230,9 +230,9 @@ end = 0
start = 0
```
## Extension
## Extension
After the students have finished their experiments. Have them play the game with a friend (using the **P2** pin) and have some contests to see who is the quickest on the draw.
After the students have finished their experiments. Have them play the game with a friend (using the **P2** pin) and have some contests to see who is the quickest on the draw.
You can find the code for this below:
@ -248,13 +248,13 @@ input.onPinPressed(TouchPin.P0, () => {
basic.clearScreen()
running = false
false_start = false
basic.pause(1000 + Math.randomRange(0, 2000))
basic.pause(1000 + randint(0, 2000))
if (!(false_start)) {
start = input.runningTime()
running = true
led.stopAnimation()
basic.clearScreen()
led.plot(Math.randomRange(0, 4), Math.randomRange(0, 4))
led.plot(randint(0, 4), randint(0, 4))
}
})
input.onPinPressed(TouchPin.P1, () => {

Просмотреть файл

@ -12,7 +12,7 @@ Add a ``||input:on shake||`` block to run code when you shake the @boardname@.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
@ -29,7 +29,7 @@ Add a ``||math:pick random||`` block to pick a random number from `1` to `3` and
```blocks
let hand = 0;
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
})
```
@ -44,7 +44,7 @@ Place an ``||logic:if||`` block under the ``||math:pick random||`` and check whe
```blocks
let hand = 0;
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
if (hand == 1) {
basic.showLeds(`
# # # # #
@ -72,7 +72,7 @@ Click the **(+)** button to add an ``||logic:else||`` section.
```blocks
let hand = 0;
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
if (hand == 1) {
basic.showLeds(`
# # # # #
@ -82,7 +82,7 @@ input.onGesture(Gesture.Shake, () => {
# # # # #
`)
} else {
}
})
```
@ -94,7 +94,7 @@ Add a ``||basic:show leds||`` block inside the ``||logic:else||``. Make a pictur
```blocks
let hand = 0;
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
if (hand == 1) {
basic.showLeds(`
# # # # #
@ -128,7 +128,7 @@ Get one more ``||basic:show leds||`` block and put it in the ``||logic:else if||
```blocks
let hand = 0;
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
if (hand == 1) {
basic.showLeds(`
# # # # #

Просмотреть файл

@ -9,8 +9,8 @@ Massively multi-player rock paper scissors!
https://youtu.be/8ztOmdZi5Pw
<br/>
Playing rock paper scissors is usually a two player game... but it will work with many more players too!
When playing with more than two players, it becomes a team game: all players shake at the same time,
then the amount of **rocks**, **paper**, and **scissors** is tallied between all the players.
When playing with more than two players, it becomes a team game: all players shake at the same time,
then the amount of **rocks**, **paper**, and **scissors** is tallied between all the players.
Teams are formed automatically based on which tool is chosen by shaking the @boardname@. The team with the most players after the shake wins the game.
Starting with the [basic version of the RPS game](/projects/rock-paper-scissors), we are going
@ -26,7 +26,7 @@ Let's start out with the code from the original game. The basic version picks on
```blocks
let tool = 0
input.onGesture(Gesture.Shake, function() {
tool = Math.randomRange(0, 2)
tool = randint(0, 2)
if (tool == 0) {
basic.showIcon(IconNames.SmallSquare)
} else if (tool == 1) {
@ -44,7 +44,7 @@ input.onGesture(Gesture.Shake, function() {
```blocks
let tool = 0
input.onGesture(Gesture.Shake, function() {
tool = Math.randomRange(0, 2)
tool = randint(0, 2)
})
basic.forever(function() {
@ -67,7 +67,7 @@ We also set the radio group and send the device serial number (a number that uni
```blocks
let tool = 0
input.onGesture(Gesture.Shake, function() {
tool = Math.randomRange(0, 2)
tool = randint(0, 2)
})
basic.forever(function() {
@ -86,7 +86,7 @@ radio.setTransmitSerialNumber(true)
## Step 3: the team roster
All players are constantly broadcasting to the other players which tool they picked.
All players are constantly broadcasting to the other players which tool they picked.
Let's add the code that receives this status and counts it.
We'll add an **[Array](/types/array)** variable that contains all the players on the same team as the current player. This array, named ``players``, is like your team roster: it contains the list of @boardname@ serial numbers that are using the same tool as you.
@ -144,7 +144,7 @@ radio.onReceivedNumber(function (receivedNumber) {
found = player_index >= 0
if (match && !(found)) {
players.push(serialNumber)
}
}
if (!(match) && found) {
temp = players.removeAt(player_index)
}
@ -158,7 +158,7 @@ What if some of the other players leave the game? They would stop broadcasting t
```block
input.onGesture(Gesture.Shake, function() {
let players: number[] = [0]
let tool = Math.randomRange(0, 2)
let tool = randint(0, 2)
})
```
@ -176,7 +176,7 @@ basic.forever(function() {
## The final code
Now, it's time to glue together all the pieces of our program.
Now, it's time to glue together all the pieces of our program.
Go carefully through all the steps and assemble the various features. Eventually, it should look
like the following program here. Download and play it with your friend**ssss**!
@ -202,7 +202,7 @@ radio.onReceivedNumber(function (receivedNumber) {
})
input.onGesture(Gesture.Shake, function() {
players = [0]
tool = Math.randomRange(0, 2)
tool = randint(0, 2)
})
basic.forever(function() {
radio.sendNumber(tool)

Просмотреть файл

@ -38,7 +38,7 @@ Choose a random number between 0 and 9.
```blocks
let randomNbr = 0
input.onGesture(Gesture.ScreenUp, () => {
randomNbr = Math.randomRange(0, 10)
randomNbr = randint(0, 10)
basic.showNumber(randomNbr)
})
```
@ -50,7 +50,7 @@ let randomNbr = 0
input.onGesture(Gesture.ScreenUp, () => {
randomNbr = 0
while (randomNbr < 1) {
randomNbr = Math.randomRange(0, 10)
randomNbr = randint(0, 10)
}
basic.showNumber(randomNbr)
})
@ -104,7 +104,7 @@ Before the game starts, decide how many rounds will be played or for how long ro
>* Player 2s @boardname@ is displaying a 6
>* The player (1 or 2) that correctly says “2 times 6 (or 6 times 2) equals 12” would win the “round”.
6. Player 3 then adds to the score:
>* If a third @boardname@ was programmed to keep score, Player 3 should press button ``A`` if Player 1 won the round or button ``B`` if Player 2 won the round.
>* If a third @boardname@ was programmed to keep score, Player 3 should press button ``A`` if Player 1 won the round or button ``B`` if Player 2 won the round.
>* If only two @boardname@s are being used, Player 3 should keep score on paper.
7. At the end of a set of rounds (or end of specified time), the total score for both players should be recorded on paper. If the third @boardname@ was programmed to keep score, Player 3 should display the scores from the @boardname@ and write them down on a score sheet. This sheet would typically have the players names on it, not player numbers since they can switch positions.
@ -115,7 +115,7 @@ If time permits, players should switch positions (e.g., Player 1 becomes Player
1. If there are enough people to play in groups of 4, Player 3 would say “Salute!” and the sum or product of the two cards, as usual. Player 4 would be the score keeper and referee on any ties OR have an additional @boardname@ with a number displayed and players need to calculate using all three @boardname@s with numbers displayed.
2. Older players could create this game for younger ones making sure to use an appropriate number range for the grade level. The older players, or the older and younger players together, could make some kind of headband to hold the @boardname@ on the forehead. The older players would then teach the younger players how the game works.
3. If only using two @boardname@s and you want to keep score:
Add the code to keep score to one of the @boardname@s being used and use the ``A`` and ``B`` buttons to keep score on that @boardname@.
Add the code to keep score to one of the @boardname@s being used and use the ``A`` and ``B`` buttons to keep score on that @boardname@.
## References

Просмотреть файл

@ -37,7 +37,7 @@ Pick a ``||math:pick a random||`` number and ``||basic:show||`` it on the screen
```spy
input.onGesture(Gesture.Shake, function() {
basic.showNumber(Math.randomRange(0, 10))
basic.showNumber(randint(0, 10))
})
```
@ -47,7 +47,7 @@ A typical dice shows values from `1` to `6`. Change the minimum and maximum valu
```spy
input.onGesture(Gesture.Shake, function() {
basic.showNumber(Math.randomRange(1, 6))
basic.showNumber(randint(1, 6))
})
```

Просмотреть файл

@ -38,7 +38,7 @@ input.onGesture(Gesture.LogoUp, function () {
## Step 4
The items in the ``||arrays:text list||`` are numbered ``0`` to ``length - 1``.
The items in the ``||arrays:text list||`` are numbered ``0`` to ``length - 1``.
Add code to pick a ``||math:random||`` ``||variables:index||``.
```spy
@ -46,20 +46,20 @@ let text_list: string[] = []
let index = 0
input.onGesture(Gesture.LogoUp, function () {
// @highlight
index = Math.randomRange(0, text_list.length - 1)
index = randint(0, text_list.length - 1)
})
```
## Step 5
Add code to ``||basic:show||`` the value of the item stored at ``||variables:index||`` in
Add code to ``||basic:show||`` the value of the item stored at ``||variables:index||`` in
``||arrays:text list||``.
```spy
let text_list: string[] = []
let index = 0
input.onGesture(Gesture.LogoUp, function () {
index = Math.randomRange(0, text_list.length - 1)
index = randint(0, text_list.length - 1)
// @highlight
basic.showString(text_list[index])
})
@ -94,7 +94,7 @@ pointing ``||input:up||``. This is the gesture for a pass.
```spy
input.onGesture(Gesture.ScreenUp, function () {
})
```

Просмотреть файл

@ -29,7 +29,7 @@ is caught holding the potato.
let timer = 0
input.onButtonPressed(Button.A, function () {
// @highlight
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
})
```
@ -40,7 +40,7 @@ Add code to ``||basic:show an icon||`` to indicate that the game has started.
```spy
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
// @highlight
basic.showIcon(IconNames.Chessboard)
})
@ -55,7 +55,7 @@ greater than `0`. When `timer` value becomes `0` or less, the game is over.
```spy
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
basic.showIcon(IconNames.Chessboard)
// @highlight
while (timer > 0) {
@ -71,7 +71,7 @@ Inside the ``||loops:while||`` loop, add code to ``||variables:decrease||`` the
```spy
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
basic.showIcon(IconNames.Chessboard)
while (timer > 0) {
// @highlight
@ -89,7 +89,7 @@ input.onButtonPressed(Button.A, function () {
```spy
let timer = 0
input.onButtonPressed(Button.A, function () {
timer = Math.randomRange(5, 15)
timer = randint(5, 15)
basic.showIcon(IconNames.Chessboard)
while (timer > 0) {
timer += -1

Просмотреть файл

@ -24,8 +24,8 @@ between `0` to `100` when pin **0** is pressed.
```spy
input.onPinPressed(TouchPin.P0, function() {
basic.showNumber(Math.randomRange(0, 100))
})
basic.showNumber(randint(0, 100));
});
```
## Step 3
@ -39,8 +39,8 @@ Insert code to ``||basic:show||`` the ``"LOVE METER"`` message on the screen whe
```spy
basic.showString("LOVE METER")
input.onPinPressed(TouchPin.P0, function() {
basic.showNumber(Math.randomRange(0, 100))
})
basic.showNumber(randint(0, 100));
});
```
## Step 5

Просмотреть файл

@ -14,7 +14,7 @@ Add an ``||input:on shake||`` event to run code when you shake the @boardname@.
```spy
input.onGesture(Gesture.Shake, () => {
})
```
@ -27,7 +27,7 @@ on the LEDs.
```spy
let hand = 0
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
})
```
@ -38,7 +38,7 @@ input.onGesture(Gesture.Shake, () => {
```spy
let hand = 0
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
if (hand == 1) {
basic.showLeds(`
# # # # #
@ -65,7 +65,7 @@ Click on the **SHAKE** button in the simulator. If you try enough times, you sho
```spy
let hand = 0
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
if (hand == 1) {
basic.showLeds(`
# # # # #
@ -93,7 +93,7 @@ Now, when the ``||math:random||`` number in ``hand`` is `2` we want to ``||basic
```spy
let hand = 0
input.onGesture(Gesture.Shake, () => {
hand = Math.randomRange(1, 3)
hand = randint(1, 3)
if (hand == 1) {
basic.showLeds(`
# # # # #

Просмотреть файл

@ -21,7 +21,7 @@ Instead of passing a real potato around while a real clock counts down, we are g
![Using radio to send a potato](/static/mb/projects/tele-potato/radio-potato.jpg)
Now, what does it mean to have a number represent a potato? Well, we need to **model** the clock as **a number** being tossed around with the potato. We do this so that we can play the game using the radio. So what is so special about this potato clock? It ticks down the time and when it reaches 0, it rings.
Now, what does it mean to have a number represent a potato? Well, we need to **model** the clock as **a number** being tossed around with the potato. We do this so that we can play the game using the radio. So what is so special about this potato clock? It ticks down the time and when it reaches 0, it rings.
To keep track of things, let's have a variable called **potato**:
@ -56,13 +56,13 @@ To make the game less predictable, we use the ``||math:pick random||`` block to
```blocks
let potato = 0
input.onButtonPressed(Button.AB, () => {
potato = Math.randomRange(10, 20)
potato = randint(10, 20)
})
```
### Sending the potato
Sending the potato is done by shaking the @boardname@. If the **potato** variable is positive,
Sending the potato is done by shaking the @boardname@. If the **potato** variable is positive,
we have the potato and we can send it. After sending it, we set the **potato** variable to `-1` since we don't have it anymore.
```blocks
@ -89,7 +89,7 @@ radio.onReceivedNumber(function (receivedNumber) {
### Ticking the clock
Making the clock tick down is done with a ``||loops:forever||`` loop.
Making the clock tick down is done with a ``||loops:forever||`` loop.
* If the **potato** is equal to `0` (``potato == 0``), KABOOM! you lose!
* If the **potato** variable is negative (``potato < 0``), we don't have the potato so we clear the screen.
@ -129,7 +129,7 @@ input.onGesture(Gesture.Shake, () => {
}
})
input.onButtonPressed(Button.AB, () => {
potato = Math.randomRange(10, 20)
potato = randint(10, 20)
})
radio.setGroup(1)
potato = -1

Просмотреть файл

@ -17,7 +17,7 @@ This program shows a number from `2` to `9` when you shake the @boardname@.
```blocks
forever(function() {
if (input.isGesture(Gesture.Shake)) {
let x = Math.randomRange(2, 9)
let x = randint(2, 9)
basic.showNumber(x)
}
})

Просмотреть файл

@ -1,6 +1,6 @@
# On Button Pressed
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens, like when a button is pressed).
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens, like when a button is pressed).
This handler works when button `A` or `B` is pressed, or `A` and `B` together.
When you are using this function in a web browser, click the buttons on the screen instead of the ones
on the @boardname@.
@ -18,7 +18,7 @@ https://www.youtube.com/watch?v=t_Qujjd_38o
## Example: count button clicks
This example counts how many times you press the `A` button.
This example counts how many times you press the `A` button.
Each time you press the button, the [LED screen](/device/screen) shows the `count` variable getting bigger.
```blocks
@ -36,7 +36,7 @@ This example shows a number from 1 to 6 when you press the `B` button.
```blocks
input.onButtonPressed(Button.B, () => {
let dice = Math.randomRange(0, 5) + 1
let dice = randint(0, 5) + 1
basic.showNumber(dice)
})
```

Просмотреть файл

@ -19,7 +19,7 @@ This program shows a number from `2` to `9` when you shake the @boardname@.
```blocks
input.onGesture(Gesture.Shake,() => {
let x = Math.randomRange(2, 9)
let x = randint(2, 9)
basic.showNumber(x)
})
```

Просмотреть файл

@ -56,7 +56,7 @@ The events related to background melody get triggered by a melody that is played
```
control.inBackground(function () {
basic.pause(Math.randomRange(0, 5000))
basic.pause(randint(0, 5000))
music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)
})
music.onEvent(MusicEvent.BackgroundMelodyStarted, function () {

Просмотреть файл

@ -42,7 +42,7 @@ Place the ``||basic:show number||`` and ``||Math:pick random||`` blocks in an ``
```blocks
input.onGesture(Gesture.Shake, () => {
basic.showNumber(Math.randomRange(0, 10))
basic.showNumber(randint(0, 10))
})
```
@ -52,7 +52,7 @@ A typical dice shows values from `1` to `6`. So, in ``||Math:pick random||``, do
```blocks
input.onGesture(Gesture.Shake, () => {
basic.showNumber(Math.randomRange(1, 6))
basic.showNumber(randint(1, 6))
})
```

Просмотреть файл

@ -7,7 +7,7 @@ Place a ``||input:on shake||`` block so when you shake the @boardname@, it wil
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
@ -16,13 +16,13 @@ input.onGesture(Gesture.Shake, () => {
Add a ``tool`` variable to store a random number computed with ``||math:pick random||``.
When you shake the @boardname@, it should pick a random number from `0` to `2`
and store it in the variable `tool`. (This variable is named `tool` because
and store it in the variable `tool`. (This variable is named `tool` because
rock, paper, and scissors are the tools you use to challenge your friends!)
```blocks
let tool = 0;
input.onGesture(Gesture.Shake, () => {
tool = Math.randomRange(0, 3)
tool = randint(0, 3)
})
```
@ -36,7 +36,7 @@ check whether ``tool`` is equal to ``0``.
```blocks
let tool = 0;
input.onGesture(Gesture.Shake, () => {
let tool = Math.randomRange(0, 3)
let tool = randint(0, 3)
if (tool == 0) {
}
})
@ -50,7 +50,7 @@ picture of a piece of paper.
```blocks
let tool = 0;
input.onGesture(Gesture.Shake, () => {
let tool = Math.randomRange(0, 3)
let tool = randint(0, 3)
if (tool == 0) {
basic.showLeds(`
# # # # #
@ -73,7 +73,7 @@ Click on the **(+)** at the bottom of the ``if`` block to add an ``else if`` sec
```blocks
let tool = 0;
input.onGesture(Gesture.Shake, () => {
let tool = Math.randomRange(0, 3)
let tool = randint(0, 3)
if (tool == 0) {
basic.showLeds(`
# # # # #
@ -94,7 +94,7 @@ Place a ``||basic:show leds||`` block under the else if and draw a **rock** imag
```blocks
let tool = 0;
input.onGesture(Gesture.Shake, () => {
let tool = Math.randomRange(0, 3)
let tool = randint(0, 3)
if (tool == 0) {
basic.showLeds(`
# # # # #
@ -125,7 +125,7 @@ That's why you can use an ``else`` instead of an ``else if``.
```blocks
let tool = 0;
input.onGesture(Gesture.Shake, () => {
let tool = Math.randomRange(0, 3)
let tool = randint(0, 3)
if (tool == 0) {
basic.showLeds(`
# # # # #