Change docs to randomInt
This commit is contained in:
@ -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.random(4)
|
||||
action = Math.randomInt(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.random(3)
|
||||
let action = Math.randomInt(3)
|
||||
```
|
||||
|
||||
## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
|
||||
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
let action = Math.randomInt(3)
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150)
|
||||
}
|
||||
@ -29,7 +29,7 @@ if (action == 0) {
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let action = Math.random(3)
|
||||
let action = Math.randomInt(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.random(3)
|
||||
let action = Math.randomInt(3)
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150)
|
||||
}
|
||||
@ -49,7 +49,7 @@ if (action == 1) {
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.random(3)
|
||||
let action = Math.randomInt(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.random(3)
|
||||
let action = Math.randomInt(3)
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150)
|
||||
}
|
||||
@ -69,7 +69,7 @@ if (action == 2) {
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.random(3)
|
||||
let action = Math.randomInt(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.random(5);
|
||||
Math.randomInt(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.random(5)
|
||||
eggX = Math.randomInt(5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
@ -50,7 +50,7 @@ basic.forever(() => {
|
||||
led.plot(basketX1, 4)
|
||||
if (eggY1 > 4) {
|
||||
eggY1 = -1
|
||||
eggX1 = Math.random(5)
|
||||
eggX1 = Math.randomInt(5)
|
||||
}
|
||||
if (eggY1 == 4) {
|
||||
if (basketX1 == eggX1) {
|
||||
@ -89,7 +89,7 @@ basic.forever(() => {
|
||||
led.plot(basketX2, 4)
|
||||
if (eggY2 > 4) {
|
||||
eggY2 = -1
|
||||
eggX2 = Math.random(5)
|
||||
eggX2 = Math.randomInt(5)
|
||||
}
|
||||
if (eggY2 == 4) {
|
||||
if (basketX2 == eggX2) {
|
||||
@ -126,7 +126,7 @@ basic.forever(() => {
|
||||
led.plot(basketX3, 4)
|
||||
if (eggY3 > 4) {
|
||||
eggY3 = -1
|
||||
eggX3 = Math.random(5)
|
||||
eggX3 = Math.randomInt(5)
|
||||
}
|
||||
if (eggY3 == 4) {
|
||||
if (basketX3 == eggX3) {
|
||||
|
@ -52,7 +52,7 @@ let eggX = 2
|
||||
let eggY = 0
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
eggX = Math.randomInt(5)
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -22,7 +22,7 @@ basic.forever(() => {
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
eggX = Math.randomInt(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.random(3)
|
||||
Math.randomInt(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.random(6)
|
||||
let roll = Math.randomInt(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.random(6);
|
||||
let roll = Math.randomInt(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.random(6);
|
||||
let roll = Math.randomInt(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.random(6);
|
||||
let roll = Math.randomInt(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.random(6);
|
||||
let roll = Math.randomInt(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.random(6);
|
||||
let roll = Math.randomInt(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.random(4);
|
||||
let roll = Math.randomInt(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.random(4) + 2;
|
||||
let roll = Math.randomInt(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.random(6)
|
||||
let roll = Math.randomInt(6)
|
||||
```
|
||||
|
||||
## 2. If the variable "roll" equals 5, write the code that will plot the image below
|
||||
@ -19,7 +19,7 @@ let roll = Math.random(6)
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let roll = Math.random(6)
|
||||
let roll = Math.randomInt(6)
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
@ -39,7 +39,7 @@ if (roll == 5) {
|
||||
|
||||
```blocks
|
||||
|
||||
let roll = Math.random(6)
|
||||
let roll = Math.randomInt(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.random(6)
|
||||
let roll = Math.randomInt(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.random(6)
|
||||
let roll = Math.randomInt(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.random(3)
|
||||
Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(10)
|
||||
})
|
||||
|
||||
```
|
||||
@ -31,7 +31,7 @@ Show the random number on the screen.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
let x = Math.randomInt(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.random(9)
|
||||
let x = Math.randomInt(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.random(9)
|
||||
let x = Math.randomInt(9)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
|
@ -24,14 +24,14 @@ input.onButtonPressed(Button.A, () => {
|
||||
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.random(10)
|
||||
let randomNumber = Math.randomInt(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.random(10)
|
||||
let randomNumber = Math.randomInt(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.random(10)
|
||||
let randomNumber = Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
```
|
||||
|
@ -12,7 +12,7 @@ coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.random(coll.length)
|
||||
let index = Math.randomInt(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.random(coll.length)
|
||||
let index = Math.randomInt(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.random(coll.length)
|
||||
let index = Math.randomInt(coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
|
@ -76,7 +76,7 @@ coll.push("cow")
|
||||
|
||||
```blocks
|
||||
let coll: string[] = []
|
||||
let index = Math.random(coll.length)
|
||||
let index = Math.randomInt(coll.length)
|
||||
let word = coll[index]
|
||||
```
|
||||
|
||||
|
@ -193,8 +193,8 @@ while (true) {
|
||||
}
|
||||
if (hero.isTouching(food)) {
|
||||
game.addScore(1);
|
||||
food.set(LedSpriteProperty.X, Math.random(5));
|
||||
food.set(LedSpriteProperty.Y, Math.random(5));
|
||||
food.set(LedSpriteProperty.X, Math.randomInt(5));
|
||||
food.set(LedSpriteProperty.Y, Math.randomInt(5));
|
||||
}
|
||||
|
||||
}
|
||||
@ -241,8 +241,8 @@ while (true) {
|
||||
}
|
||||
if (hero.isTouching(food)) {
|
||||
game.addScore(1);
|
||||
food.set(LedSpriteProperty.X, Math.random(5));
|
||||
food.set(LedSpriteProperty.Y, Math.random(5));
|
||||
food.set(LedSpriteProperty.X, Math.randomInt(5));
|
||||
food.set(LedSpriteProperty.Y, Math.randomInt(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.random(3)
|
||||
Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(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.random(10)
|
||||
let x = Math.randomInt(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.random(9)
|
||||
let x = Math.randomInt(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.random(9)
|
||||
let x = Math.randomInt(9)
|
||||
```
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ Learn how to creating **conditionals**, `if condition do` to conditionally run c
|
||||
|
||||
```cards
|
||||
if (true) {}
|
||||
Math.random(3)
|
||||
Math.randomInt(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.random(3)
|
||||
let randomNumber = Math.randomInt(3)
|
||||
|
||||
});
|
||||
```
|
||||
@ -47,7 +47,7 @@ basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen();
|
||||
let randomNumber = Math.random(3);
|
||||
let randomNumber = Math.randomInt(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.random(3)
|
||||
let randomNumber = Math.randomInt(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.random(3)
|
||||
let randomNumber = Math.randomInt(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.random(3)
|
||||
let randomNumber = Math.randomInt(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.random(2)
|
||||
let randomNumber = Math.randomInt(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.random(4)
|
||||
let randomNumber = Math.randomInt(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.random(4)
|
||||
let randomNumber = Math.randomInt(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.random(4)
|
||||
let randomNumber = Math.randomInt(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.random(3)
|
||||
let x = Math.randomInt(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.random(3)
|
||||
let x = Math.randomInt(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.random(3)
|
||||
let x = Math.randomInt(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.random(3)
|
||||
let x = Math.randomInt(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.random(3)
|
||||
let randomNumber = Math.randomInt(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.random(3)
|
||||
Math.randomInt(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.random(4)
|
||||
let randomArrow = Math.randomInt(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.random(4)
|
||||
let randomArrow = Math.randomInt(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.random(4)
|
||||
let randomArrow = Math.randomInt(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.random(4)
|
||||
let randomArrow = Math.randomInt(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.random(8)
|
||||
let randomArrow = Math.randomInt(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.random(8)
|
||||
let randomArrow = Math.randomInt(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.random(4)
|
||||
let randomArrow = Math.randomInt(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.random(4)
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let randomArrow = Math.random(4);
|
||||
let randomArrow = Math.randomInt(4);
|
||||
if (randomArrow == 1) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
@ -44,7 +44,7 @@ if (randomArrow == 1) {
|
||||
<br />
|
||||
|
||||
```blocks
|
||||
let randomArrow = Math.random(4);
|
||||
let randomArrow = Math.randomInt(4);
|
||||
if (randomArrow == 2) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
|
@ -32,7 +32,7 @@ basic.showLeds(`
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
let x = 0
|
||||
Math.random(3)
|
||||
Math.randomInt(3)
|
||||
if (true) {}
|
||||
basic.showString("Hello!")
|
||||
```
|
||||
|
@ -34,7 +34,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(2)
|
||||
let random = Math.randomInt(2)
|
||||
})
|
||||
```
|
||||
|
||||
@ -49,7 +49,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(2)
|
||||
let random = Math.randomInt(2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -71,7 +71,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(2)
|
||||
let random = Math.randomInt(2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
|
@ -16,7 +16,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(2)
|
||||
let random = Math.randomInt(2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -45,7 +45,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(3)
|
||||
let random = Math.randomInt(3)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -75,7 +75,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(2)
|
||||
let random = Math.randomInt(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.random(4)
|
||||
let random = Math.randomInt(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.random(4)
|
||||
let random = Math.randomInt(4)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH", 150)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let random = Math.random(2)
|
||||
let random = Math.randomInt(2)
|
||||
if (random == 0) {
|
||||
basic.showString("TRUTH")
|
||||
} else {
|
||||
@ -53,7 +53,7 @@ basic.showLeds(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
`);
|
||||
Math.random(2);
|
||||
Math.randomInt(2);
|
||||
basic.showString("TRUTH");
|
||||
if (true) {} else {}
|
||||
"TRUTH";
|
||||
|
Reference in New Issue
Block a user