Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perfect if / else if / else

Chris Hildebran
Chris Hildebran
700 Points

Why this error [StudentsCode.cs(15,5): error CS1525: Unexpected symbol `if']?Only a closing bracket on this line!

I keep going back and forth between code and results but dont see a coorelation.

CodeChallenge.cs
string input = Console.ReadLine();
int temperature = int.Parse(input);

if (temperature< 21)
{
System.Console.WriteLine("Too Cold!");
}

Else if (temperature == 21)
{
System.Console.WriteLine("Just Right.");
{

    Else if (temperature > 22)
{
System.Console.WriteLine("Too hot!");   
}

else
{
System.Console.WriteLine("asdf");
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! In two places, you have miscapitalized "else" as "Else". Always assume in programming that everything is case-sensitive. Note how your very last else is orange meaning that it's a reserved word, while your two Else are white. It means that the compiler believes Else is an undefined variable. Correcting the capitalization should get you past that error.

Hope this helps! :sparkles:

edited for additional tip

:bulb: On a side note, whenever you see a compiler error and it says something like error on line 15 but you can't find anything wrong with line 15 at all, start looking upwards in your code. 99% of the time, it's something that's happening before that line that's incorrect.