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 trialGeovanny Reyes
3,876 PointsHas anyone done this code challenge? not sure where to put the switch statement
help appreciated
class Point {
var x: Int
var y: Int
init(x: Int, y: Int){
self.x = x
self.y = y
}
}
class Machine {
var location: Point
init() {
self.location = Point(x: 0, y: 0)
}
func move(direction: String) {
print("Do nothing! Im a machine!")
}
}
// Enter your code below
2 Answers
Ryan Doyle
8,587 PointsI have done it, but I don't remember the instructions. I do remember that the switch statement goes within the scope of the "func move { the switch statement goes in here}" because that move function is telling the Machine where to "go."
Steven Parker
231,248 PointsFirst, you need to create a Robot class (subclass of Machine). Then inside your new class you will create a move method. The switch (which is optional) would go in that move method.
You can also pass the challenge using only conditional (if) statements and no switch.
Geovanny Reyes
3,876 Pointsthank you!
Geovanny Reyes
3,876 PointsGeovanny Reyes
3,876 Pointsthank you!