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 trialThiago Silva
715 PointsThe code mentioned in this video did not compile because it is not possible to execute this.answer = answer.toLowerCase.
This happens because answer is declared as a String and not char, which makes sense for me. The case is, why did it compile for Craig if the code is the same? I have double-checked it. The variable answer cannot be changed to char because the would break the previous logic of the code.
1 Answer
andren
28,558 PointsIt compiled because there is nothing wrong with it.
While you are right that a char
cannot be stored in a String
variable nothing in the code you quote deals with chars. toLowerCase
is a method that exists on String
objects and returns a lower case String
. Since answer
(the field variable) and answer
(the parameter) are both strings the line of code you highlighted is not incorrect at all.
There is a toLowerCase
method that can be used on chars "Character.toLowerCase()
" but that is not the method used in the project.
If you are getting error messages about converting between char
and String
then you have probably declared one of the variables wrongly, or mistyped some of the code in the project.