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.

JavaScript

Code Challenge: Java Variables Explained

I don't know what I am doing wrong. The challenge is to Set the favoriteColor variable to your favorite color. You might need to move some things around and add or change some text; using this string: favoriteColor String equals "";

My answer is: String favoriteColor = "purple" ;

I'm not passing this challenge. What am I doing wrong? TIA!

1 Answer

Sandra Weber
Sandra Weber
1,531 Points

Hi E Mac,

This one confused me too. The answer is actually to set the variable's value on a different line, after its declaration.

Hope this helps!

Thanks Sandra, but now I'm feeling really dumb. I typed the following:

String favoriteColor =

"purple" ;

That didn't work. Perhaps I'm not understanding what the variable's value is. I thought it was the color in quotes ("purple").

Thanks again for your help.

Sandra Weber
Sandra Weber
1,531 Points

Hi E Mac,

It can be a bit confusing! To change a variable's value after it's been declared you can simply leave off the "String" part, like so

favoriteColor = "purple";

So, putting that line after the variable's declaration (without changing the declaration) will change the value from what it was (I think it starts off as blank, "") to purple.

Thanks Sandra! I forgot to add the myname line and leaving off the "string" part is a helpful hint.