11/12. Filling out the Cases


#1

I have passed this lesson, but my code only works when you press the left arrow. it does not work for the other directions. Someone please tell me why. Here is my 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:
				$('img').animate({up: "+=10px"}, 'fast');
				break;
			// Right Arrow Pressed
			case 39:
				$('img').animate({right: "+=10px"}, 'fast');
				break;
			// Down Arrow Pressed
			case 40:
				$('img').animate({down: "-=10px"}, 'fast');
				break;
		}
	});
});

Thank you :grin:


#2

Sorry I changed my code now. Only the right arrow does not work.


11/12 | Mario runs, but doesn't work
#3

There are no directions in CSS, and .animate() only recognizes the left and top boundaries (reference axes).

Use,

top: /* plus or minus */
left: /* plus or minus */

#4

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