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 trialTim Watkins
16,034 PointsNeed help not sure how to figure out the wording
func move( direction: Direction) { // Enter your code below switch(direction) { case Direction.up: location.y += 1
case Direction.down: location.y -= 1
case Direction.left: location.x -= 1
case Direction.right: location.x += 1
}}}
class Point {
var x: Int
var y: Int
init(x: Int, y: Int) {
self.x = x
self.y = y
}
}
enum Direction {
case left
case right
case up
case down
}
class Robot {
var location: Point
init() {
self.location = Point(x: 0, y: 0)
}
func move( direction: Direction) {
// Enter your code below
switch(direction) {
case Direction.up: location.y += 1
case Direction.down: location.y -= 1
case Direction.left: location.x -= 1
case Direction.right: location.x += 1
}}}
4 Answers
Ollie King
10,194 PointsHi Tim, I believe you've made the tiniest mistake (you'll probably kick yourself once you realise). So after the word "switch" you've put "direction" in parentheses. Remove them and the code should work! - Hope this helps :)
Tim Watkins
16,034 Pointsit says now You need to provide an implementation for the move method
Ollie King
10,194 PointsOh, ok. Would you be able to paste in the code you're now trying to use?
Tim Watkins
16,034 Pointsclass Point { var x: Int var y: Int
init(x: Int, y: Int) {
self.x = x
self.y = y
}
}
enum Direction { case left case right case up case down }
class Robot { var location: Point
init() {
self.location = Point(x: 0, y: 0)
}
func move( direction: Direction) {
// Enter your code below
switch direction {
case Direction.up: location.y += 1
case Direction.down: location.y -= 1
case Direction.left: location.x -= 1
case Direction.right: location.x += 1
}}}
This is the code I'm using now
Ollie King
10,194 PointsHmmm.. strange..
This is what I have:
class Point {
var x: Int
var y: Int
init(x: Int, y: Int) {
self.x = x
self.y = y
}
}
enum Direction {
case left
case right
case up
case down
}
class Robot {
var location: Point
init() {
self.location = Point(x: 0, y: 0)
}
func move(_ direction: Direction) {
// Enter your code below
switch direction {
case Direction.up: location.y += 1
case Direction.down: location.y -= 1
case Direction.right: location.x += 1
case Direction.left: location.x -= 1
}
}
}
Tim Watkins
16,034 PointsAwesome that work Thanks. I removed the underscore thought was old syntax but didt need to do that Thanks again
Ollie King
10,194 PointsHaha! I didn't know if you had or it was the forum pulling it out of what you copied in.. I've had that happen to me a few times. No worries Tim :)
Happy coding!