What is wrong with this code?

This is my code:


however, whenever I run it, it gives me the error “expecting }, found ‘else’”. I’ve gone through it multiple times and I have no idea whats going wrong. Please help.

Line 8 and 12
No Semicolon. :slight_smile:

there are semicolons on those lines. when I run it, it tells me “expecting }, found ‘else’”, yet all my {}s are in the right location

No you got me wrong. you have to get rid of the semicolons.

1 Like

In the future, please paste your code as text instead of as a screenshot.

@Jan is correct: you have extra semicolons in your code.

Note that it’s possible to put code inside { } curly brackets. This is fine:

void setup(){
  size(500, 500);
  {
    background(32);
    ellipse(250, 250, 50, 50);
  }
} 

You can also put a semicolon after an if statement:

if( thingIsTrue );

This basically means: if thingIsTrue, then do nothing.

What you have is a combination of both of the above concepts:

if(mousePressed);
{
  triangle(mouseX, height-mouseY, 58, 662, 86, 27);
  ...
}

This code says: if mousePressed, then do nothing. After that, always execute the code inside these { } curly brackets.

You’re getting an error because then you have an else statement, which doesn’t make sense in the above context.

Jan is right: get rid of the semicolons after your if statements.

1 Like