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
26,783 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
26,783 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.