11. Filling out the cases


#1

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

Oops, try again. Did you call the .animate() function on your $('img') for each of the three additional cases?

$(document).ready(function() {
    $(document).keydown(function(key) {
        switch(parseInt(key.which,10)) {
			// Left arrow key pressed
			case 37:
				$('img').animate({left: "-=10px"}, 'fast');
				break;
			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;
		}
	});
});

The code works totally fine, but the error keeps popping up.


#2

Perhaps it is a browser issue?


#3

Maybe CA also checks whether you wrote the default case as well?


#4

Found it! Just before case 38, you need the following comment in your code:

// Up Arrow Pressed

#5

No, they don't need the default case here.


#6

You don't need it. But it's actually good practice to add a default case. Also it's kind of strange, that he needs a comment in his code in order for it to work.


#7

The lesson doesn't want the default case.... And I agree it's strange that you need to add the comment, but it's the only solution that works. (I did the lesson myself).


#8

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