Expected unqualified-id before 'else' in Arduino Starter kit proj. 2

Hello all,
I'm a beginner, and I've read several threads in other forums about my error and I just can't figure it out.

Details:

  1. I'm running an Arduino UNO board on a PC
  2. I'm trying to complete Project #2 in the "Arduino Starter Kit" (aka "Spaceship" project)
  3. Specifically, I'm trying to turn different LEDs on by pressing the button
  4. The LEDs work with the code below, but nothing happens when I press the button.

Troubleshooting I've done so far:

  1. I know the button is working based on a previous project
  2. I made sure that the curly braces are all paired
  3. The error I'm getting: "expected unqualified-id before 'else'" seems to be related to line 21 (where "else" shows up), but I can't see anything in previous lines that should cause a problem.

Here is my code:

int switchState = 0;
void setup() {
  // put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);

}

void loop(){
  switchState = digitalRead(2);
  
  if (switchState == LOW)
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
  
}
else {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);

}

I'd really appreciate any guidance. I'm new to this, so please be kind :wink:

All the best,
Louis

if (switchState == LOW)
{
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}

Here is your code Auto formatted in the IDE

int switchState = 0;
void setup()
{
  // put your setup code here, to run once:
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(2, INPUT);
}

void loop()
{
  switchState = digitalRead(2);
  if (switchState == LOW)
    digitalWrite(3, HIGH);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
}
else
{
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);
}

Note the indentation after the if. Only the digitalWrite(3, HIGH) is dependant on the test returning true so there are unconditionally executed statements between the if and the else, hence the error

To compound the problem, where is the closing brace of the loop() function ?