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 trialChristopher Meyers
Courses Plus Student 3,706 PointsThere is a typo in this question. Too many ")" at the end.
There is a typo in this question, there are too many ")" at the end:
We need to add getter and setter methods to the fahrenheit property of the Temperature class. Add a getter method to the access the value of the fahrenheit property. Then add a setter method. When the user assigns a value to the fahrenheit property, the setter method will calculate and assign a value to the celsius property. (Note: Celsius = (Fahrenheit-32)/1.8))
* I changed the description to remove the content that was automatically posted with the actual part of the question that contains the typo. Apologies for the confusion.
Christopher Meyers
Courses Plus Student 3,706 PointsThanks Srinivasan. But the content you saw was automatically posted in by the system. The actual issue I was referring to occurs in the question's description.
Srinivasan Senthil
2,266 PointsSrinivasan Senthil
2,266 Points2 brackets for Class. 2 brackets for the computed property 2 brackets for Getter method 2 brackets for Setter method.
The code should be corrected: class Temperature { var celsius: Float = 0.0 var fahrenheit: Float {
Instead of using "return (Fahrenheit-32)/1.8", please use "celsius = newValue - 32 / 1.8" OR " return celsius = newValue - 32 / 1.8"
The place you got confused is:
Computed property has 2 brackets. Getter is part of a computed property so it should have two brackets. total 4.
Getter method is only to get the value. You cannot assign a new value to that variable. So to assign it with some other variable, you will have to use "newValue".
In your example, you used the get method to get the value of Fahrenheit. To calculate Celsius, you would need to subtract the Fahrenheit with 32 and divide by 1.8. So you to pass the Fahrenheit value you will have to use the keyword "newValue".
Hope this helps.