Add another key to your Piano and learn about the ‘if - else if’ statement that will allow your code to have many ‘options’ about how it runs!
The code in the editor below already works Just plug in your Code Piano and press upload to see what it does! Tinker with it and make changes to see what each line of code controls.
Watch the videos for line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!
Can you complete the challenge? Change the code in your code editor above. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!
These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.
New Concept: ‘If’ and ‘else if’ statements
In this program, you see that the code can react to two different inputs and react differently to each of them. Every time the void loop runs, the code checks the conditions of the ‘if’ and ‘else if’ statements until it finds one that is true. Then, it runs the action that goes along with the true condition.
Remember that the program runs from top to bottom, so the first ‘if’ statement gets checked before the next ‘else if’ statement. Once a ‘true’ condition is found, the rest of the ‘if’ and ‘else if’ statements are skipped. This means that the higher up in the code an ‘else if’ statement is, the higher priority it has if you hold down multiple buttons at once.