// Copyright 2007, Sandeep Gangadharan // For more free scripts go to http://www.sivamdesign.com/scripts/
 
 

Honk your horn with a button on Code Car. What sounds will you make?

The code below already works and is ready to upload! Upload the code to Code Car and see what happens. Then, you'll 'take apart' the code to learn what each piece of the program does.

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!

Challenges

How many can you complete? Change the code according to the challenges below. 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: Continuing with 'if' statements

The 'if' statement is worth spending another lesson on, since it changes the entire way you can think about programming. Code Car only has one type of physical input- the button, but you can trigger any sort of output with it.

To put it another way, anything that you can run inside a void loop, you can also run inside an 'if' statement. It could be one line of code or it could be 20 lines of code - there is no limit. When you do that, the code inside the 'if' statement only runs when a certain condition is true. If you didn't get enough challenge out of this lesson, think about some of the code in previous lessons, like songs, that you could now trigger with an 'if' statement.

Quiz

If you're having trouble, try to run an experimental program or look at the example code to help you find the answer.

What types of code commands can run as an 'action' inside an 'if' statement?



An 'if' statement always has two basic parts. What are they?