11/12:Why am I getting an error?


#1

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');
				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;
		}
	});
});

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

Thanks in advance!


#2

Hi,

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

Thanks


#3

Just tried it, and it worked. Thanks!

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


#4

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


#5

Total aside concerning indentation and switch()...

    switch (expression) {
    case 1: //
        break;
    case 2: //
        break;
    case 3: //
        break;
    case 4: //
        break;
    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.


#6

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


#7

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