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 trialColton Wiethorn
1,723 PointsNot sure what the issue is here but I am unable to find a solution here or online. Please advise. Thanks
Not sure what the issue is here but I am unable to find a solution here or online. Please advise. Thanks
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! I\'m a machine!")
}
}
// Enter your code below
class Robot: Machine {
func Override move(direction: String) {
switch direction {
case "Up": location.y += 1
case "Down": location.y -= 1
case "Left": location.x -= 1
case "Right": location.x += 1
default: break
}
}
}
2 Answers
Daniel Santos
34,969 PointsColton,
First, in the challenge that I am getting now the signature of the move function in the Machine
class is func move(_ direction: String)
. If you didn't modified this, you should report a bug for that challenge, but I would make sure first.
Now the real issue in your code is that when you override the method, the override
keyword should first. For example:
override func move(_ direction: String)
Also, override is all lower case, in your code you are writing Override
. Fix these issues and let me know anything.
Hope I helped.
-Daniel
Colton Wiethorn
1,723 PointsThank you Daniel! I failed to write the signature of the move function correctly. There is no bug, I removed it. Correct answer worked when I wrote the override function as: override func move(_ direction: String)
Thanks again