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 trialkask
7,509 PointsEnums and object challenge 1
Needing a bit of help not quite understanding what it wants me to do.
"In the editor below you have two objects - a struct named Point and a class named Robot. The Robot stores its location as a point instance and contains a move function.
The task of this challenge is to complete the implementation for move. Move takes a parameter of type Direction which is an enumeration listing the possible movement directions.
When you tell the robot to move up (by specifying Direction.Up as the argument), the y coordinate should increase by 1. Similarly moving down means the y coordinate decreases by 1, moving right means the x coordinate increases by 1 and finally left means x decreases by 1."
3 Answers
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsDepending on the direction of the move, you're going to increment or decrement the robot's location x or y coordinate. Let me know if you need more than that.
Gibson Smiley
1,923 PointsWhat was the correct code?
Gibson Smiley
1,923 PointsNever mind, I got it:
switch direction {
case .Up: location.y += 1
case .Down: location.y -= 1
case .Right: location.x += 1
case .Left: location.x -= 1
}```
Joshua Hardy
17,317 Pointsswitch direction {
case .up: location.y += 1
case .down: location.y -= 1
case .right: location.x += 1
case .left: location.x -= 1
}
kask
7,509 Pointskask
7,509 PointsOk finally got it thank you :)