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

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,558 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!!