11. Filling out the cases



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

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


Perhaps it is a browser issue?


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


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

// Up Arrow Pressed


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


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.


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).


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