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 trialYONGJIN KIM
Full Stack JavaScript Techdegree Graduate 20,287 PointsHow come teacher did not add playToken() to handleKeydown()?
In the video, the teacher only codes playToken() method and jump to the demo page. It would be better to mention adding playToken() to handleKeydown() in the video. It could make students confused, although it is easy to catch it.
2 Answers
Steven Parker
231,236 PointsYour own assessment of "It could make students confused" is probably the best guess as to why it wouldn't be included in the instruction.
But spotting alternatives and potentially more compact/efficient solutions is a good indication of your learning progress and grasp of the material!
Timothy Andes
7,897 PointsI think it was a mistake that they didn't show that part of the challenge. Within Game.js, the handleKeydown(e)
method should now look like this, for reference:
/**
* Branches code depending on what key the player presses.
* @param {object} e - keydown event object.
*/
handleKeydown(e) {
if (this.ready) {
if (e.key === "ArrowLeft") {
this.activePlayer.activeToken.moveLeft();
} else if (e.key === "ArrowRight") {
this.activePlayer.activeToken.moveRight(this.board.columns);
} else if (e.key === "ArrowDown") {
this.playToken();
}
}
}