Welcome to the forty-second of Altitude Foundation’s #MicroChallenges2020
Today’s challenge will help you ensure your algorithm has all the necessary information
What’s a Micro Challenge?
These challenges are short activities to help you develop, revise or refresh your coding skills, posted every Monday, Wednesday and Friday.
Micro Challenge #42
This week, we are exploring debugging
The Challenge:
Today’s challenge focuses on ensuring your algorithm has all the necessary information it needs to have to work. This week, we have looked at three algorithms. However, you may have noticed that one algorithm is not complete. Our sock matching game is missing some key information. What is it?
- A sock matching game (JavaScript)
input.onButtonPressed(Button.A, function () {
basic.showSting(“1st!”)
basic.pause(500)
basic.showString(“” + (Socks_1[index]))
basic.pause(500)
basic.showString(“2nd”)
basic.pause(500)
basic.showString(“” + (Socks_2index_2))
}
if (Socks_1[index] == Socks_2index_2) {
Basic.showString(“Matched pair”)
Basic.showString(“Try Again”)
Basic.clearScreen()
} else {
Basic.showString(“Hurra!!!”)
})
Review it:
- If you want a clue, check out Challenge 18, the original inspiration for this programme!
- You can use the MakeCode editor to check the JavaScript errors or Trinket to check Python.
Advanced:
- The sock matcher is incomplete – could you complete it using the MakeCode editor linked above?
Share it
We would love to see what you have created! Please send any pictures, videos, or files of your activities to us – either via Facebook, Twitter or Instagram using #MicroChallenges2020 or to challenges@altitudefoundation.org. If you are emailing them to us, please let us know if you are happy for us to share your stuff on our social media platforms (with credit, of course).