Fix randomInt
This commit is contained in:
parent
b5814709f8
commit
6f148c14e0
@ -18,7 +18,7 @@ When you compare two Numbers, you get a Boolean value, such as the comparison `x
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.randomInt(5)
|
||||
let x = Math.randomRange(0, 5)
|
||||
if(x < 5) {
|
||||
basic.showString("low");
|
||||
} else {
|
||||
|
@ -200,14 +200,14 @@ 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.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
```
|
||||
|
||||
Next, let’s 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.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
```
|
||||
|
||||
@ -238,7 +238,7 @@ 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.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
```
|
||||
|
||||
@ -253,7 +253,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.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
basic.pause(1000)
|
||||
basic.clearScreen()
|
||||
|
@ -62,7 +62,7 @@ let column = 0
|
||||
let index = 0
|
||||
input.onButtonPressed(Button.AB, () => {
|
||||
for (let index = 0; index <= 4; index++) {
|
||||
list[index] = Math.randomInt(5) + 1
|
||||
list[index] = Math.randomRange(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.randomInt(5) + 1
|
||||
list[index] = Math.randomRange(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.randomInt(5) + 1
|
||||
list[index] = Math.randomRange(0, 5) + 1
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
|
@ -196,7 +196,7 @@ let player1Turn = false
|
||||
let spin = 0
|
||||
let delay = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
if (player1Turn == true && Math.randomInt(4) < 3) {
|
||||
if (player1Turn == true && Math.randomRange(0, 4) < 3) {
|
||||
basic.clearScreen()
|
||||
delay = 0
|
||||
while (delay < 500) {
|
||||
@ -241,7 +241,7 @@ input.onGesture(Gesture.Shake, () => {
|
||||
} else if (player1Turn) {
|
||||
basic.showString("Crash!")
|
||||
player1Turn = false
|
||||
} else if (Math.randomInt(4) < 3) {
|
||||
} else if (Math.randomRange(0, 4) < 3) {
|
||||
basic.clearScreen()
|
||||
delay = 0
|
||||
while (delay < 500) {
|
||||
@ -305,7 +305,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.randomInt(4) < 3) {
|
||||
if (player1Turn == true && Math.randomRange(0, 4) < 3) {
|
||||
|
||||
}
|
||||
})
|
||||
|
@ -34,7 +34,7 @@ Here's an example mod:
|
||||
```blocks
|
||||
let hand = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
hand = Math.randomInt(3)
|
||||
hand = Math.randomRange(0, 3)
|
||||
if (hand == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
|
@ -59,7 +59,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
basic.showNumber(p2)
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
if (Math.randomInt(p1 + p2 - 1 + 1) + 1 <= p1) {
|
||||
if (Math.randomRange(0, p1 + p2 - 1 + 1) + 1 <= p1) {
|
||||
basic.showString("A")
|
||||
} else {
|
||||
basic.showString("B")
|
||||
@ -118,10 +118,10 @@ let previous_roll = 0
|
||||
input.onButtonPressed(Button.AB, () => {
|
||||
previous_roll = 0
|
||||
if (4 <= previous_roll) {
|
||||
yes_or_no = Math.randomInt(8)
|
||||
yes_or_no = Math.randomRange(0, 8)
|
||||
}
|
||||
if (4 > previous_roll) {
|
||||
yes_or_no = Math.randomInt(5)
|
||||
yes_or_no = Math.randomRange(0, 5)
|
||||
}
|
||||
if (2 < yes_or_no) {
|
||||
basic.showString("YES")
|
||||
@ -132,7 +132,7 @@ input.onButtonPressed(Button.AB, () => {
|
||||
}
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
current_roll = Math.randomInt(6)
|
||||
current_roll = Math.randomRange(0, 6)
|
||||
basic.showNumber(current_roll + 1)
|
||||
basic.pause(5000)
|
||||
basic.clearScreen()
|
||||
|
@ -96,7 +96,7 @@ Steps:
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
for (let index = 0; index <= 4; index++) {
|
||||
led.plot(index, Math.randomInt(5))
|
||||
led.plot(index, Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
```
|
||||
@ -117,7 +117,7 @@ Here is the complete program:
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
for (let index = 0; index <= 4; index++) {
|
||||
led.plot(index, Math.randomInt(5))
|
||||
led.plot(index, Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
|
@ -150,7 +150,7 @@ basic.forever(() => {
|
||||
} else {
|
||||
game.addScore(1)
|
||||
ball.set(LedSpriteProperty.Y, 0)
|
||||
ball.set(LedSpriteProperty.X, Math.randomInt(5))
|
||||
ball.set(LedSpriteProperty.X, Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
@ -163,7 +163,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
dodger.change(LedSpriteProperty.X, 1)
|
||||
}
|
||||
})
|
||||
ball = game.createSprite(Math.randomInt(5), 0)
|
||||
ball = game.createSprite(Math.randomRange(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.randomInt(5))
|
||||
ball.set(LedSpriteProperty.X, Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
@ -195,7 +195,7 @@ input.onButtonPressed(Button.B, () => {
|
||||
dodger.change(LedSpriteProperty.X, 1)
|
||||
}
|
||||
})
|
||||
ball = game.createSprite(Math.randomInt(5), 0)
|
||||
ball = game.createSprite(Math.randomRange(0, 5), 0)
|
||||
dodger = game.createSprite(2, 4)
|
||||
game.setScore(0)
|
||||
```
|
||||
|
@ -39,7 +39,7 @@ the @boardname@ will return a random Number between 0 and the parameter limit.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.randomInt(10))
|
||||
basic.showNumber(Math.randomRange(0, 10))
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -75,8 +75,8 @@ basic.forever(() => {
|
||||
inside = 0
|
||||
for (let i = 0; i < n; i++) {
|
||||
// generate a point within the square
|
||||
x = Math.randomInt(r + 1)
|
||||
y = Math.randomInt(r + 1)
|
||||
x = Math.randomRange(0, r + 1)
|
||||
y = Math.randomRange(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.randomInt(5), Math.randomInt(5))
|
||||
led.toggle(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
})
|
||||
```
|
@ -24,7 +24,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
basic.forever(() => {
|
||||
if (start) {
|
||||
led.toggle(Math.randomInt(5), Math.randomInt(5))
|
||||
led.toggle(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
```
|
@ -42,7 +42,7 @@ Change the global variable `action` to `math->random(4)` so that we can add a ne
|
||||
```typescript
|
||||
let action = 0;
|
||||
export function newAction() {
|
||||
action = Math.randomInt(4)
|
||||
action = Math.randomRange(0, 4)
|
||||
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.randomInt(3)
|
||||
let action = Math.randomRange(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.randomInt(3)
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150)
|
||||
}
|
||||
@ -29,7 +29,7 @@ if (action == 0) {
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let action = Math.randomInt(3)
|
||||
let action = Math.randomRange(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.randomInt(3)
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150)
|
||||
}
|
||||
@ -49,7 +49,7 @@ if (action == 1) {
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.randomInt(3)
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
@ -59,7 +59,7 @@ input.onLogoDown(() => {
|
||||
## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
|
||||
|
||||
```blocks
|
||||
let action = Math.randomInt(3)
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150)
|
||||
}
|
||||
@ -69,7 +69,7 @@ if (action == 2) {
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.randomInt(3)
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ basic.pause(300);
|
||||
input.acceleration(Dimension.X);
|
||||
Math.min(0,0);
|
||||
Math.max(0,1);
|
||||
Math.randomInt(5);
|
||||
Math.randomRange(0, 5);
|
||||
game.addScore(1);
|
||||
game.score();
|
||||
game.removeLife(1);
|
||||
|
@ -19,7 +19,7 @@ basic.forever(() => {
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.randomInt(5)
|
||||
eggX = Math.randomRange(0, 5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
@ -50,7 +50,7 @@ basic.forever(() => {
|
||||
led.plot(basketX1, 4)
|
||||
if (eggY1 > 4) {
|
||||
eggY1 = -1
|
||||
eggX1 = Math.randomInt(5)
|
||||
eggX1 = Math.randomRange(0, 5)
|
||||
}
|
||||
if (eggY1 == 4) {
|
||||
if (basketX1 == eggX1) {
|
||||
@ -89,7 +89,7 @@ basic.forever(() => {
|
||||
led.plot(basketX2, 4)
|
||||
if (eggY2 > 4) {
|
||||
eggY2 = -1
|
||||
eggX2 = Math.randomInt(5)
|
||||
eggX2 = Math.randomRange(0, 5)
|
||||
}
|
||||
if (eggY2 == 4) {
|
||||
if (basketX2 == eggX2) {
|
||||
@ -126,7 +126,7 @@ basic.forever(() => {
|
||||
led.plot(basketX3, 4)
|
||||
if (eggY3 > 4) {
|
||||
eggY3 = -1
|
||||
eggX3 = Math.randomInt(5)
|
||||
eggX3 = Math.randomRange(0, 5)
|
||||
}
|
||||
if (eggY3 == 4) {
|
||||
if (basketX3 == eggX3) {
|
||||
|
@ -52,7 +52,7 @@ let eggX = 2
|
||||
let eggY = 0
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.randomInt(5)
|
||||
eggX = Math.randomRange(0, 5)
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -22,7 +22,7 @@ basic.forever(() => {
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.randomInt(5)
|
||||
eggX = Math.randomRange(0, 5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
|
@ -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.randomInt(3)
|
||||
Math.randomRange(0, 3)
|
||||
if (true) {}
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
|
@ -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.randomInt(6)
|
||||
let roll = Math.randomRange(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.randomInt(6);
|
||||
let roll = Math.randomRange(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.randomInt(6);
|
||||
let roll = Math.randomRange(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.randomInt(6);
|
||||
let roll = Math.randomRange(0, 6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
@ -108,7 +108,7 @@ Let's also repeat these steps to show the 3, 2, and 1 on the dice. We are almost
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.randomInt(6);
|
||||
let roll = Math.randomRange(0, 6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
|
@ -8,7 +8,7 @@ Complete the following [guided tutorial](/lessons/dice-roll/activity), your code
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.randomInt(6);
|
||||
let roll = Math.randomRange(0, 6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
@ -67,7 +67,7 @@ Modify the line of code with `pick random` so that only number 1-4 can appear on
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.randomInt(4);
|
||||
let roll = Math.randomRange(0, 4);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
@ -125,7 +125,7 @@ Let's make a trick dice! Modify the line of code with `pick random` so that only
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.randomInt(4) + 2;
|
||||
let roll = Math.randomRange(0, 4) + 2;
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
|
@ -9,7 +9,7 @@ These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let roll = Math.randomInt(6)
|
||||
let roll = Math.randomRange(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.randomInt(6)
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let roll = Math.randomInt(6)
|
||||
let roll = Math.randomRange(0, 6)
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
@ -39,7 +39,7 @@ if (roll == 5) {
|
||||
|
||||
```blocks
|
||||
|
||||
let roll = Math.randomInt(6)
|
||||
let roll = Math.randomRange(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.randomInt(6)
|
||||
let roll = Math.randomRange(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.randomInt(6)
|
||||
let roll = Math.randomRange(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.randomInt(3)
|
||||
Math.randomRange(0, 3)
|
||||
basic.clearScreen()
|
||||
```
|
||||
|
||||
|
@ -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.randomInt(10)
|
||||
let x = Math.randomRange(0, 10)
|
||||
})
|
||||
|
||||
```
|
||||
@ -31,7 +31,7 @@ Show the random number on the screen.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.randomInt(10)
|
||||
let x = Math.randomRange(0, 10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
|
||||
|
@ -8,7 +8,7 @@ Complete the following [guided tutorial](/lessons/guess-the-number/activity), an
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.randomInt(9)
|
||||
let x = Math.randomRange(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.randomInt(9)
|
||||
let x = Math.randomRange(0, 9)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
|
@ -24,14 +24,14 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.randomInt(10)
|
||||
let randomNumber = Math.randomRange(0, 10)
|
||||
```
|
||||
|
||||
## 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.randomInt(10)
|
||||
let randomNumber = Math.randomRange(0, 10)
|
||||
```
|
||||
|
||||
|
||||
|
@ -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.randomInt(10)
|
||||
let randomNumber = Math.randomRange(0, 10)
|
||||
basic.showNumber(randomNumber, 150)
|
||||
```
|
||||
|
||||
|
@ -16,7 +16,7 @@ The blocks have been shuffled! Put them back together so that...
|
||||
|
||||
```shuffle
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.randomInt(10)
|
||||
let x = Math.randomRange(0, 10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
```
|
||||
|
@ -12,7 +12,7 @@ coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.randomInt(coll.length)
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
@ -34,7 +34,7 @@ coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.randomInt(coll.length)
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
@ -64,7 +64,7 @@ coll.push("sun")
|
||||
coll.push("car")
|
||||
coll.push("ant")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.randomInt(coll.length)
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
|
@ -76,7 +76,7 @@ coll.push("cow")
|
||||
|
||||
```blocks
|
||||
let coll: string[] = []
|
||||
let index = Math.randomInt(coll.length)
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
```
|
||||
|
||||
|
@ -193,8 +193,8 @@ while (true) {
|
||||
}
|
||||
if (hero.isTouching(food)) {
|
||||
game.addScore(1);
|
||||
food.set(LedSpriteProperty.X, Math.randomInt(5));
|
||||
food.set(LedSpriteProperty.Y, Math.randomInt(5));
|
||||
food.set(LedSpriteProperty.X, Math.randomRange(0, 5));
|
||||
food.set(LedSpriteProperty.Y, Math.randomRange(0, 5));
|
||||
}
|
||||
|
||||
}
|
||||
@ -241,8 +241,8 @@ while (true) {
|
||||
}
|
||||
if (hero.isTouching(food)) {
|
||||
game.addScore(1);
|
||||
food.set(LedSpriteProperty.X, Math.randomInt(5));
|
||||
food.set(LedSpriteProperty.Y, Math.randomInt(5));
|
||||
food.set(LedSpriteProperty.X, Math.randomRange(0, 5));
|
||||
food.set(LedSpriteProperty.Y, Math.randomRange(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.randomInt(3)
|
||||
Math.randomRange(0, 3)
|
||||
basic.showNumber(0)
|
||||
basic.pause(100)
|
||||
```
|
||||
|
@ -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.randomInt(10)
|
||||
let x = Math.randomRange(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.randomInt(10)
|
||||
let x = Math.randomRange(0, 10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
|
||||
|
@ -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.randomInt(10)
|
||||
let x = Math.randomRange(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.randomInt(10)
|
||||
let x = Math.randomRange(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.randomInt(10)
|
||||
let x = Math.randomRange(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.randomInt(10)
|
||||
let x = Math.randomRange(0, 10)
|
||||
basic.showNumber(x)
|
||||
basic.pause(3000)
|
||||
if (x < 4) {
|
||||
|
@ -23,7 +23,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
## 3. What does this line of code doing?
|
||||
|
||||
```blocks
|
||||
let x = Math.randomInt(9)
|
||||
let x = Math.randomRange(0, 9)
|
||||
```
|
||||
|
||||
|
||||
|
@ -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.randomInt(9)
|
||||
let x = Math.randomRange(0, 9)
|
||||
```
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ Learn how to creating **conditionals**, `if condition do` to conditionally run c
|
||||
|
||||
```cards
|
||||
if (true) {}
|
||||
Math.randomInt(3)
|
||||
Math.randomRange(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.randomInt(3)
|
||||
let randomNumber = Math.randomRange(0, 3)
|
||||
|
||||
});
|
||||
```
|
||||
@ -47,7 +47,7 @@ basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen();
|
||||
let randomNumber = Math.randomInt(3);
|
||||
let randomNumber = Math.randomRange(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.randomInt(3)
|
||||
let randomNumber = Math.randomRange(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.randomInt(3)
|
||||
let randomNumber = Math.randomRange(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.randomInt(3)
|
||||
let randomNumber = Math.randomRange(0, 3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
|
@ -11,7 +11,7 @@ basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.randomInt(2)
|
||||
let randomNumber = Math.randomRange(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.randomInt(4)
|
||||
let randomNumber = Math.randomRange(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.randomInt(4)
|
||||
let randomNumber = Math.randomRange(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.randomInt(4)
|
||||
let randomNumber = Math.randomRange(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.randomInt(3)
|
||||
let x = Math.randomRange(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.randomInt(3)
|
||||
let x = Math.randomRange(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.randomInt(3)
|
||||
let x = Math.randomRange(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.randomInt(3)
|
||||
let x = Math.randomRange(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.randomInt(3)
|
||||
let randomNumber = Math.randomRange(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.randomInt(3)
|
||||
Math.randomRange(0, 3)
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
|
@ -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.randomInt(4)
|
||||
let randomArrow = Math.randomRange(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.randomInt(4)
|
||||
let randomArrow = Math.randomRange(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.randomInt(4)
|
||||
let randomArrow = Math.randomRange(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.randomInt(4)
|
||||
let randomArrow = Math.randomRange(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.randomInt(8)
|
||||
let randomArrow = Math.randomRange(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.randomInt(8)
|
||||
let randomArrow = Math.randomRange(0, 8)
|
||||
if (randomArrow == 7) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
|
@ -15,7 +15,7 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let randomArrow = Math.randomInt(4)
|
||||
let randomArrow = Math.randomRange(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.
|
||||
@ -25,7 +25,7 @@ let randomArrow = Math.randomInt(4)
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let randomArrow = Math.randomInt(4);
|
||||
let randomArrow = Math.randomRange(0, 4);
|
||||
if (randomArrow == 1) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
@ -44,7 +44,7 @@ if (randomArrow == 1) {
|
||||
<br />
|
||||
|
||||
```blocks
|
||||
let randomArrow = Math.randomInt(4);
|
||||
let randomArrow = Math.randomRange(0, 4);
|
||||
if (randomArrow == 2) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
|
@ -32,7 +32,7 @@ basic.showLeds(`
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
let x = 0
|
||||
Math.randomInt(3)
|
||||
Math.randomRange(0, 3)
|
||||
if (true) {}
|
||||
basic.showString("Hello!")
|
||||
```
|
||||
|
@ -34,7 +34,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.randomInt(2)
|
||||
let random = Math.randomRange(0, 2)
|
||||
})
|
||||
```
|
||||
|
||||
@ -49,7 +49,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.randomInt(2)
|
||||
let random = Math.randomRange(0, 2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -71,7 +71,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.randomInt(2)
|
||||
let random = Math.randomRange(0, 2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
|
@ -16,7 +16,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.randomInt(2)
|
||||
let random = Math.randomRange(0, 2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -45,7 +45,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.randomInt(3)
|
||||
let random = Math.randomRange(0, 3)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -75,7 +75,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.randomInt(2)
|
||||
let random = Math.randomRange(0, 2)
|
||||
if (random == 1) {
|
||||
basic.showString("TRUTH")
|
||||
} else if (random == 0) {
|
||||
|
@ -7,13 +7,13 @@ 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.randomInt(4)
|
||||
let random = Math.randomRange(0, 4)
|
||||
```
|
||||
|
||||
## 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.randomInt(4)
|
||||
let random = Math.randomRange(0, 4)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH", 150)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.randomInt(2)
|
||||
let random = Math.randomRange(0, 2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -53,7 +53,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
`);
|
||||
Math.randomInt(2);
|
||||
Math.randomRange(0, 2);
|
||||
basic.showString("TRUTH");
|
||||
if (true) {} else {}
|
||||
"TRUTH";
|
||||
|
@ -257,7 +257,7 @@ input.onButtonPressed(Button.AB, () => {
|
||||
// launch game
|
||||
if (state == GameState.Pairing) {
|
||||
// pick 1 player and infect him
|
||||
patientZero = players[Math.randomInt(players.length)];
|
||||
patientZero = players[Math.randomRange(0, players.length)];
|
||||
while (patientZero.health == HealthState.Healthy) {
|
||||
radio.sendValue("infect", patientZero.id);
|
||||
basic.pause(100);
|
||||
@ -333,7 +333,7 @@ radio.onDataPacketReceived(({ time, receivedNumber, receivedString, signal, seri
|
||||
if (health == HealthState.Healthy && receivedString == "transmit") {
|
||||
serial.writeLine(`signal: ${signal}`);
|
||||
if (signal > RSSI &&
|
||||
Math.randomInt(100) > TRANSMISSIONPROB) {
|
||||
Math.randomRange(0, 100) > TRANSMISSIONPROB) {
|
||||
infectedBy = receivedNumber;
|
||||
infectedTime = input.runningTime();
|
||||
health = HealthState.Incubating;
|
||||
|
@ -18,7 +18,7 @@ show a random number from 0 to 100 when pin ``P0`` is pressed.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.randomInt(101));
|
||||
basic.showNumber(Math.randomRange(0, 101));
|
||||
});
|
||||
```
|
||||
|
||||
@ -29,7 +29,7 @@ Show ``"LOVE METER"`` on the screen when the @boardname@ starts.
|
||||
```blocks
|
||||
basic.showString("LOVE METER");
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showNumber(Math.randomInt(101));
|
||||
basic.showNumber(Math.randomRange(0, 101));
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -125,7 +125,7 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
|
||||
@ -155,13 +155,13 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
if (!(false_start)) {
|
||||
start = input.runningTime()
|
||||
running = true
|
||||
led.stopAnimation()
|
||||
basic.clearScreen()
|
||||
led.plot(Math.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
running = false
|
||||
@ -214,13 +214,13 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
if (!(false_start)) {
|
||||
start = input.runningTime()
|
||||
running = true
|
||||
led.stopAnimation()
|
||||
basic.clearScreen()
|
||||
led.plot(Math.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
running = false
|
||||
@ -247,13 +247,13 @@ input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.clearScreen()
|
||||
running = false
|
||||
false_start = false
|
||||
basic.pause(1000 + Math.randomInt(2000))
|
||||
basic.pause(1000 + Math.randomRange(0, 2000))
|
||||
if (!(false_start)) {
|
||||
start = input.runningTime()
|
||||
running = true
|
||||
led.stopAnimation()
|
||||
basic.clearScreen()
|
||||
led.plot(Math.randomInt(5), Math.randomInt(5))
|
||||
led.plot(Math.randomRange(0, 5), Math.randomRange(0, 5))
|
||||
}
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
|
@ -22,7 +22,7 @@ rock, paper, and scissors are the tools you use to challenge your friends!)
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
|
||||
```
|
||||
@ -37,7 +37,7 @@ check whether ``tool`` is equal to ``0``.
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
}
|
||||
})
|
||||
@ -51,7 +51,7 @@ picture of a piece of paper.
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
@ -74,7 +74,7 @@ Click on the gearwheel icon to open up the ``if`` editor; then drag and drop an
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
@ -95,7 +95,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.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
@ -126,7 +126,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.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
|
@ -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, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showIcon(IconNames.SmallSquare)
|
||||
} else if (tool == 1) {
|
||||
@ -44,7 +44,7 @@ input.onGesture(Gesture.Shake, () => {
|
||||
```blocks
|
||||
let tool = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
|
||||
basic.forever(() => {
|
||||
@ -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, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
|
||||
basic.forever(() => {
|
||||
@ -154,7 +154,7 @@ What if some of the other players leave the game? They would stop broadcasting t
|
||||
```block
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let players: number[] = [0]
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
})
|
||||
```
|
||||
|
||||
@ -185,7 +185,7 @@ let match = false
|
||||
let players: number[] = []
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
players = [0]
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
radio.onDataPacketReceived( ({ receivedNumber, serial: serialNumber }) => {
|
||||
match = tool == receivedNumber
|
||||
|
@ -38,7 +38,7 @@ Choose a random number between 0 and 9.
|
||||
```blocks
|
||||
let randomNbr = 0
|
||||
input.onGesture(Gesture.ScreenUp, () => {
|
||||
randomNbr = Math.randomInt(10)
|
||||
randomNbr = Math.randomRange(0, 10)
|
||||
basic.showNumber(randomNbr)
|
||||
})
|
||||
```
|
||||
@ -50,7 +50,7 @@ let randomNbr = 0
|
||||
input.onGesture(Gesture.ScreenUp, () => {
|
||||
randomNbr = 0
|
||||
while (randomNbr < 1) {
|
||||
randomNbr = Math.randomInt(10)
|
||||
randomNbr = Math.randomRange(0, 10)
|
||||
}
|
||||
basic.showNumber(randomNbr)
|
||||
})
|
||||
|
@ -32,7 +32,7 @@ This example shows a number from 1 to 6 when you press the `B` button.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
let dice = Math.randomInt(6) + 1
|
||||
let dice = Math.randomRange(0, 6) + 1
|
||||
basic.showNumber(dice)
|
||||
})
|
||||
```
|
||||
|
@ -19,7 +19,7 @@ This program shows a number from `0` to `9` when you shake the @boardname@.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake,() => {
|
||||
let x = Math.randomInt(10)
|
||||
let x = Math.randomRange(0, 10)
|
||||
basic.showNumber(x, 100)
|
||||
})
|
||||
```
|
||||
|
@ -58,7 +58,7 @@ on the screen.
|
||||
|
||||
```block
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showNumber(Math.randomInt(7))
|
||||
basic.showNumber(Math.randomRange(0, 7))
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -22,7 +22,7 @@ rock, paper, and scissors are the tools you use to challenge your friends!)
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
tool = Math.randomInt(3)
|
||||
tool = Math.randomRange(0, 3)
|
||||
})
|
||||
```
|
||||
|
||||
@ -36,7 +36,7 @@ check whether ``tool`` is equal to ``0``.
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(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.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
@ -73,7 +73,7 @@ Click on the gearwheel icon to open up the ``if`` editor; then drag and drop an
|
||||
```blocks
|
||||
let tool = 0;
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let tool = Math.randomInt(3)
|
||||
let tool = Math.randomRange(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.randomInt(3)
|
||||
let tool = Math.randomRange(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.randomInt(3)
|
||||
let tool = Math.randomRange(0, 3)
|
||||
if (tool == 0) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
|
@ -12,12 +12,6 @@ namespace Math {
|
||||
//% blockId=logic_random block="pick random true or false"
|
||||
//% help=math/random-boolean weight=0
|
||||
export function randomBoolean(): boolean {
|
||||
return true;
|
||||
//return Math.floor(Math.random() * 2) == 1;
|
||||
}
|
||||
|
||||
export function randomInt(max: number): number {
|
||||
return max;
|
||||
//return Math.floor(Math.random() * max);
|
||||
return Math.floor(Math.randomRange(0, 1) * 2) == 1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user