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 trialAnneke Keller
5,667 PointsSwift Enums and Structs first Challenge Task 2 of 2
I can't get it solved. This is my code so far:
Challenge: Create a variable called turtleSpeed and assign it the Raw value of the member Slow.
enum Speed: Int {
case Slow = 10
case Medium = 50
case Fast = 100
}
var turtleSpeed = Speed(rawValue:10)
Can someone help?
4 Answers
Jhoan Arango
14,575 PointsHello Anneke Keller
This challenge wants you to create a variable and add the rawValue of the member Slow. Basically you have to access the enum you created and then use the rawValue from the member Slow. Remember than if you want to access values, you have to use the dot syntax. If you passed this challenge by doing the following, then you passed the challenge correctly, otherwise you may have passed the challenge with an incorrect answer.
enum Speed: Int {
case Slow = 10
case Medium = 50
case Fast = 100
}
var turtleSpeed = Speed.Slow.rawValue
// Here we are accessing one the enum's members rawValue.
Good luck
Lara DiLiberti
2,942 Pointsenum Speed: Int {
case Slow = 10
case Medium = 50
case Fast = 100
}
var turtleSpeed = 10
Jhoan Arango
14,575 PointsI modified your answer, so that you code can be read. Nothing in the code was changed :)
Anneke Keller
5,667 PointsThanks! I really appriciate your help.
Anneke Keller
5,667 PointsThanks! Especially for explaining your answer so well.
Lara DiLiberti
2,942 PointsLara DiLiberti
2,942 PointsI didn't realize the challenge could accept an incorrect answer! Thanks for the explanation.
Jhoan Arango
14,575 PointsJhoan Arango
14,575 PointsLara DiLiberti:
Since you provided the same rawValue to the compiler it assumed it was correct. Remember that the rawValue was an Int, and you gave it an Int for an answer, as it was expecting.