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 trialRob Fleming
6,634 Pointsall i get is an error i dont know how to fix this swift_lint.swift:43:1: error: expected declaration
swift_lint.swift:43:1: error: expected declaration
^
the 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) {
// Enter your code below
// We need to switch on the parameter we pass in.
switch direction { // The code block contains all the cases inside the braces.
case .Up: // Each case separates what it is from what it does with a :
self.location.y += 1 // We reference the location object property for y like this.
case .Down: // We can leave out the Direction and start with . for the known type.
self.location.y -= 1
case .Left:
self.location.x -= 1
case .Right:
self.location.x += 1
}
}
2 Answers
Joe Beltramo
Courses Plus Student 22,191 PointsYou are missing a closing bracket at the end of your file.
Mackenzy Douyon
iOS Development Techdegree Student 2,913 Points//HELP! none of those solutions works for me
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 .Up:
return location.y += 1
case .Down:
return location.y -= 1
case .Right:
return location.x += 1
//case .Left:
default:
return location.x -= 1
}
}
}
// posible solution #2 /* switch direction { case .Up: location.y++ case .Down: location.y-- case .Right: location.x++ case .Left: location.x-- } */
// posible solution #3
/* switch direction { case .Up: self.location.y += 1 case .Down: self.location.y -= 1 case .Left: self.location.x -= 1 case .Right: self.location.x += 1 } */
/* switch direction { case .Up: return location.y += 1 case .Down: return location.y -= 1 case .Right: return location.x += 1 default: return location.x -= 1 } */
Rob Fleming
6,634 PointsRob Fleming
6,634 PointsThank you