Lecture 21 Unexpected Symbol 'else'

I THINK I have copied the script exactly as it appears on screen, but when I try to run it I get this error and it will not allow me to play:
Assets/Hacker.cs(41,8): error CS1525: Unexpected symbol `else’
Did I do something wrong and I just don’t see it?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour {

int level;

// Use this for initialization
void Start () {
    ShowMainMenu("Strong Bad, Yer Looking Prooty Hot.");
}

void ShowMainMenu (string greeting) {
    Terminal.ClearScreen();
    Terminal.WriteLine(greeting);
    Terminal.WriteLine("What would you like to hack into?");
    
    Terminal.WriteLine("Press 1 for Bubs Concession Stand");
    Terminal.WriteLine("Press 2 for the King of Town");
    Terminal.WriteLine("Enter your selection:");

}

void OnUserInput(string input)
{
    if (input == "menu")
    {
        ShowMainMenu("Strong Bad, Yer Looking Prooty Hot.");
    }
        else if (input == "1");
    {
        level = 1;
        StartGame();
    }
        else if (input == "2") ;
    {
        level = 2;
        StartGame();
    }
    else if (input == "007")
    {
        Terminal.WriteLine("Please select a level, Mr Bond");
    }
    else
    {
        Terminal.WriteLine("Please choose a valid level, dorkface.");
    }
  }
}

“else if (input == “2”) ;”

you have semicolons ( “;” ) after the “else if” statements in several places, which confuses the parser.

Should be something like:
… }
else if (input == “1”)
{
level = 1;
StartGame();
}
else if (input == “2”)
{
level = 2;

Thanks Todd. I did miss that. I’m still very confused by all of this. Hopefully that will change as the course progresses.

Privacy & Terms