if and else are not working

When I was trying to do the second project of the Arduino starter kit if and else were not being recognized. I think I am missing something obvious.

int switchState = 0;
void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop(){
switchState = digitalRead(2);

// this is a comment
if (switchState == LOW) {
//the button is not pressed
digitalWrite(3, HIGH); // green LED
digitalWrite(4, LOW); // red LED
digitalWrite(5, LOW); // red LED
}
else { // the button is pressed
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
delay(250); // wait for a quarter second
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
} // go back to the beginning of the loop

We are certainly missing seeing your code.

Please use code tags.

Read this before posting a programming question

How to use this forum

Looking in my crystal ball I see semicolons on the ends of the if/else lines. I wonder what I will see when the code is posted.

UKHeliBob:
Looking in my crystal ball I see semicolons on the ends of the if/else lines. I wonder what I will see when the code is posted.

Mine is showing an assignment in the if condition.

Mine is showing something that is hard to describe ...

I think I am missing something obvious.

Yep. An understanding of the physical characteristics of an input pin and how to wire a switch.

If you have wired the switch correctly, which I doubt, you have missed telling us how it is wired AND why you chose to wire it in a more complicated fashion than needed.

And you have missed an understanding of how to use this forum. DO NOT EDIT YOUR INITIAL POST. When told to post your code, or other details. do it in a response.

pandatech:
I think I am missing something obvious.

Now you're missing this:-

pandatech:
When I was trying to do the second project of the Arduino starter kit if and else were not being recognized.

The compiler certainly recognizes "if" and "else". So can you describe what you are seeing? A compiler error? Or when you test it, what happens? The LEDs stay on? They stay off? They change unexpectedly? They don't change when you press the switch?

I was trying to upload a picture of the code but I could not get it to work. When I type if and else in the code they just stay grey and do not turn a different color.

Copy the code and paste it here, in code tags.

Read this before posting a programming question

How to use this forum

I believe I posted those links before.

The code you posted above compiles. The colour of the words doesn't affect how they work.