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 trialmoath alqutoob
2,450 Pointsthis code make me crazy
plz help me to understand this code
$(document).ready(function() {
$(document).keydown(function(key) {
switch(parseInt(key.which,10)) {
// Left arrow key pressed
case 37:
$('img').animate({left: "-=10px"}, 'fast');
break;
// Up Arrow Pressed
case 38:
// Put our code here
break;
// Right Arrow Pressed
case 39:
// Put our code here
break;
// Down Arrow Pressed
case 40:
// Put our code here
break;
}
});
});
1-keydown(function(key) why he put key in function what this key do
switch(parseInt(key.which,10))
10? key.which parseInt and the code
1 Answer
diego sepulveda
3,502 Points1-. He put key as parameter in that function because is a callback function, google that, so when the document is ready this means that page has load completely excute this function, saying $(document).keydown(function(key){}) this means listen to any key and excute this function and passing the parameter key you can use it to see what key was pressed
Rich Donnellan
Treehouse Moderator 27,696 PointsRich Donnellan
Treehouse Moderator 27,696 PointsFormatted your code. From the Markdown Cheatsheet: