A fun way to teach kids to code is to celebrate an event. Last New Year's Eve, my kids celebrated the coming of the new year by building a countdown timer. As a Dad, I am proud to see how my son tried to explain the steps involved. Asking him parts of the code and what he learned. Check out the video:
Here are the blocks we used at https://makecode.microbit.org/
Here's the Javascript code:
let star2: Image = null
let star1: Image = null
let countingdown = false
let counter = 0
input.onButtonPressed(Button.A, () => {
counter += 1
})
input.onButtonPressed(Button.B, () => {
countingdown = true
})
star1 = images.createImage(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
star2 = images.createImage(`
. . . . .
. . # . .
. # # # .
. . # . .
. . . . .
`)
counter = 3
countingdown = false
basic.forever(() => {
basic.showNumber(counter)
if (countingdown == true) {
basic.pause(1000)
counter += -1
if (counter <= 0) {
countingdown = false
for (let i = 0; i < 4; i++) {
star1.showImage(0)
basic.pause(200)
star2.showImage(0)
basic.pause(200)
}
basic.showString("HAPPY NEW YEAR!")
}
}
})
If this project made you interested to learn more about Micro:Bit, javascript or about MakeCode, click the thumbs up/respect button and follow me. Thanks.
Comments