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 Refactoring

Tony Lawrence
Tony Lawrence
3,056 Points

Trouble with the Code Challenge After the Refactor Video.

Hi all,

I'm having trouble trying to figure out what the Code Challenge after watching the Refactor Video. I think if there were //comments added, I could get more of an idea of what the challenge wants.

This is the code:

string input = "22";

int converted = int.Parse(input);

bool wheelsAreRound = true;

string downcased = "DoNuTs".ToLower();

bool success = (downcased == "donuts");

double total = 0;

From what I can gather, this is what I could come up with:

var input = "22";

var converted = int.Parse(input);

while (true) 

{
    continue;

var downcased = "DoNuTs".ToLower();

    if (false){
     break;   
    } 
}

var total = 0.0;

It states to me that it's incorrect with: " Did you delete the wheelsAreRound variable?" Am I thinking too much into detail when this challenge is looking for a simple answer?

Thanks

2 Answers

Damien Watson
Damien Watson
27,419 Points

Hi Tony,

I think that it may be the 'thinking too much' issue, basic result of the following will see you through:

var input = "22";

var converted = int.Parse(input);

var wheelsAreRound = true;

var downcased = "DoNuTs".ToLower();

var success = (downcased == "donuts");

var total = 0.0;
Tony Lawrence
Tony Lawrence
3,056 Points

Thanks. I thought it was looking for that answer, but that just seems too simple.

Damien Watson
Damien Watson
27,419 Points

Lol, I know, it's usually the simpler answer that gets you.

The thing that really bugged me about this was the 'var success' statement.

You see, i thought that if you took the 'bool' away from the statement, it would then become a String variable, not a Boolean variable and therefore, it would be wrong.

But yeah, i don't know...

Also, i think your 'While loop' would just loop forever since you used 'continue;'

It would be a infinite loop.

Correct me if i'm wrong, but the code after 'continue;' would never run.

And the code in the 'if' statement would also never be false, since there isn't really a condition to be met, i suppose.

=)

I also got this challenge wrong by thinking it was harder.