Exercise 8 not working for me, why?


#1
$(document).ready(function() {
    $(document).keydown(function(key) {
        switch(parseInt(key.which,10)) {
			// Left arrow key pressed
			case 37:
				$('img').animate({left: "+=10px"}, '500');
				break;
			// Up Arrow Pressed
			case 38:
			    	$('img').animate({top: "-=10px"}, '500');
				// Put our code here
				break;
			// Right Arrow Pressed
			case 39:
			    	$('img').animate({right: "-=10px"}, '500');
				// Put our code here
				break;
			// Down Arrow Pressed
			case 40:
			    	$('img').animate({bottom: "-=10px"}, '500');
				// Put our code here
				break;
		}
	});
});

not work for me..why?


8. The .keydown() Event
#2

Hi Nico,

Don't use the bottom and right keywords. You need to control the image's position by adding or subtracting 10px from left or top :slight_smile:


#3

.......what is missing?


#4

@chipsolver75782 Nothing, but you need to use left and right for all directions, you can't use right and bottom.


#5

you can show me the code?


#6

@chipsolver75782 No, that's not allowed. Take your best shot at following my instructions, and if you're still having trouble, post your code and the error message you're getting.


#7

the error look me is "Please press the required key down on [object Object]."


#8

@chipsolver75782 Click on the image, then press at least one of your arrow keys. Then wait two seconds and return to the editor.


#9

ok work..sorry :confused:


#10

@chipsolver75782 No worries, glad it's working now :slight_smile:


#11

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.