pxt-calliope/docs/reference/js/lessons/running-time/challenges.md

31 lines
765 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# running time challenges
My script. #docs
**Challenge 0**
2016-04-13 17:27:45 +02:00
Great job! You have successfully completed the [Running Time tutorial](/lessons/running-time/tutorial) . You have a forever loop that declares a variable in it that holds the running time in milliseconds of the micro:bit and then shows the seconds on the LED screen.
2016-03-26 00:47:20 +01:00
```
basic.forever(() => {
let now = input.runningTime()
basic.showNumber(now / 1000, 150)
})
```
**Challenge 1**
When button A is pressed, reset the time by subtracting the current time from the variable now.
```
basic.forever(() => {
let now1 = input.runningTime()
basic.showNumber(now1 / 1000, 150)
})
if (input.buttonIsPressed("A")) {
let now2 = 0 // ***
}
```
* Run the code to see if it works as expected.