Bug Hunt! Test your Troubleshooting.

You may have already run into some errors in modifying or writing your own code. Don't worry, studies have shown that almost half of all code 'compiles' result in an error! 

The code below has some errors sprinkled in it. Before you run the code, read through it and look for the errors, called bugs. Can you find them? Try to fix each one and then see if the code runs. 

/* * Press button 9 to honk the horn on Code Car using a variable */ int horn = 9; //an integer variable called 'horn' void setup(){ pinMode(horn,INPUT_PULLUP); //button to activate the horn pinMode(2,OUTPUT); //speaker on Code Car } void loop(){ //if the pushbutton is pressed, start playing a tone if(digitalRead(Horn)==LOW) { //if the horn button is pressed... tone(2,250); //the code between the braces will run } else { //an else statement runs when the 'if' condition isn't true noTone(2); //silence the horn } } // (c) 2022 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 



Need a hint? Click here.