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 trialGurpreet Bhachu
3,188 PointsKeep getting a compiler error but I think I am doing everything right
This is the function I've created. It ended up being similar to other solutions on the message board. I'm confused why I keep getting compiler errors...
Firstly, I've updated the enum to include Upper cased direction... I don't know where I am going wrong...
Maybe I need to use a self or a return statement but i've tried both these and it keeps telling me I have a compiler error...
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) {
switch direction {
case .Left: location.x -=1
case .Right: location.x +=1
case .Up: location.y +=1
case .Down: location.y -=1
}
}
}
2 Answers
KRIS NIKOLAISEN
54,971 PointsYou shouldn't update existing code unless specifically asked to do so. I changed the enum back to lowercase then added spaces between = and 1 in the switch statement and it passed.
switch direction {
case .left: location.x -= 1
case .right: location.x += 1
case .up: location.y += 1
case .down: location.y -= 1
}
Gurpreet Bhachu
3,188 PointsI did not at first but tried a bunch of things when I could not get it to pass. I tried it again with the whitespace between the 1 and the ='s and it worked... thank you!