12/12 finished the challenge, but not sure about the keys


#1


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


Okay the code is not misbehaving in any way, the image moves perfectly. My issue is with the wording in the instructions. It says "Great work! Your sprite now moves to the left, right, up, and down when you hit the a, s, w, and d keys." My image only moves when I use the arrow keys on the keyboard. It doesn't move when I use the asdw keys though. I tried using the asdw and I got an error message saying to press the correct moving keys, which happen to be the arrow keys. Is that okay? Have they just worded the exercise badly or...should the image be able to move with asdw keys?


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


#2

Those instructions date back to the original exercise when letter keys were used instead of the arrow keys. You can make it true just by adding to your cases:

case 37:
case 65:  // ...

case 38:
case 87:  // ...

case 39:
case 68:  // ...

case 40:
case 83:  // ...

Now you can use both sets of keys. This is not an expectation of the lesson checker, though, but it will not interfere, either.


#3

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