12. You did it! (Super Mario)



The exercise description says that I'm should be able to move to the left, right, up, and down when you hit the a, s, w, and d keys. I can only do it with the arrow keys. What's the error in 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');
			// Up Arrow Pressed
			case 38:
				// Put our code here
				$('img').animate({top: "-=10px"}, 'fast');
			// Right Arrow Pressed
			case 39:
				// Put our code here
				$('img').animate({left: "+=10px"}, 'fast');
			// Down Arrow Pressed
			case 40:
				// Put our code here
				$('img').animate({top: "+=10px"}, 'fast');


Read carefully

What other effects would you want to add in order to make a basic game?



Hi @rcodeman! I have to change the case values to, 65 (a), 83 (s), 87 (w), 68 (d). It's not explained but I searched for event.which and discovered these keys values to the computer.


[12/12] You Did It!

Right :slight_smile:



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