12. You did it! (Super Mario)


#1



https://www.codecademy.com/en/courses/web-beginner-en-JwhI1/2/4?curriculum_id=50a3fad8c7a770b5fd0007a1


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');
				break;
			// Up Arrow Pressed
			case 38:
				// Put our code here
				$('img').animate({top: "-=10px"}, 'fast');
				break;
			// Right Arrow Pressed
			case 39:
				// Put our code here
				$('img').animate({left: "+=10px"}, 'fast');
				break;
			// Down Arrow Pressed
			case 40:
				// Put our code here
				$('img').animate({top: "+=10px"}, 'fast');
				break;
		}
	});
});


#2

Read carefully

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

@teowey


#3

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.

Right?


[12/12] You Did It!
#4

Right :slight_smile:

@rcodeman


#5

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