Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Getting this error while using if/else if /else challenge

StudentsCode.cs(9,5): error CS0103: The name temprature' does not exist in the current context StudentsCode.cs(13,9): error CS0103: The nametemprature' does not exist in the current context Compilation failed: 2 error(s), 0 warnings

CodeChallenge.cs
string input = Console.ReadLine();
int temperature = int.Parse(input);
if (temprature == 21|22 )
{
Console.WriteLine("Just Right.");
}
else if(temprature <= 21)
{
Console.WriteLine("Too Cold!");
}
else
{
Console.WriteLine("Too Hot!");
}

1 Answer

Steven Parker
Steven Parker
229,771 Points

:point_right: The variable name is "temperature".

Note the "e" following the "p". But the variable name you referenced is "temprature" (with no "e" after the "p"), and no variable of that name was ever declared.

Also, you probably did not intend to do a bitwise OR (|) on this line:

if (temprature == 21|22 )

The bitwise OR expression "21|22" is equivalent to 23, which is likely not what you wanted to compare with. What you probably intended was a logical OR (||), which requires a complete comparison on each side. It would look like this (with the variable name also corrected):

if (temperature == 21 || temperature == 22)