11/12:Why am I getting an error?


I'm on lesson 11/12: Filling out the cases, and I keep getting the error "Oops, try again. Did you call the .animate() function on your $('img') for each of the three additional cases?". Even though, yes I did call .animate(), and it makes Mario move and everything.

Here's 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:
				$('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');

So... What's wrong?
If you need anymore information, please tell me.

Thanks in advance!



this is going to annoy you, its right, its just the exercise is looking for single quotes instead of double. If you change $("img") to $('img') it should work.

Both are valid, but I do prefer to use single quotes then selecting things, and double quotes when outputting text



Just tried it, and it worked. Thanks!

And you were right, it did kind of annoy me. : )


Thx got the same problem. i switched " to ' and it worked fine


Total aside concerning indentation and switch()...

    switch (expression) {
    case 1: //
    case 2: //
    case 3: //
    case 4: //
    default: //

Consider what happens with break. Does flow jump out of the case or the switch? Answer: The switch. So it would appear we do not need to indent the case, and probably shouldn't.


why we cant using as right and down as well? looking like the code does not understand us.


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