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

Carlos Pizarro
PLUS
Carlos Pizarro
Courses Plus Student 1,878 Points

Bummer: I entered "21". I expected "Just right." but got "Just right" instead. Why is it wrong?

This is from the C# if else exercise. It prints the right thing so i do not know why it is wrong

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

if (temperature < 21) {
    System.Console.WriteLine("Too cold!");
} 
else if (temperature <= 22) 
{
    System.Console.WriteLine("Just right");
} 
else 
{
    System.Console.WriteLine("Too hot!");
}

1 Answer

andren
andren
28,538 Points

The challenge checker is often very picky when it comes to strings, it requires that the string match the example provided to the exact letter. In this case the issue is that you are missing a period at the end of the string. If you add one like this:

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

if (temperature < 21) {
    System.Console.WriteLine("Too cold!");
} 
else if (temperature <= 22) 
{
    System.Console.WriteLine("Just right."); // Added . to the string
} 
else 
{
    System.Console.WriteLine("Too hot!");
}

Then your code will be accepted.

Carlos Pizarro
Carlos Pizarro
Courses Plus Student 1,878 Points

No way!!!! hahaha i was shocked when i saw the error. I will be more careful next time with the text. Thank you so much!!