pxt-calliope/docs/reference/js/lessons/guess-the-number/activity.md
2016-03-25 16:47:20 -07:00

987 B

guess the number activity

guess the number with math random. #microbit #docs

~avatar avatar

@video td/videos/guess-the-number-0

Welcome! This tutorial will help you create a guess the number game! Let's get started!

~

To create a new script, go to the Create Code page and tap New Project under Touch Develop.

Add an event handler when button A is pressed.

input.onButtonPressed("A", () => {
})

Create a local variable of type number x and set it to a random number using math->random. math->random(10) generates a random number between 0 and 10 excluded.

input.onButtonPressed("A", () => {
    let x = Math.random(10)
})

Show the random number on the screen.

input.onButtonPressed("A", () => {
    let x1 = Math.random(10)
    basic.showNumber(x1, 150)
})

~avatar avatar

Excellent, you're ready to continue with the challenges!

~