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

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.