11.Filling out cases... but dude doesn't move


#1



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


Hi. I passed the lesson however my little guy does not move in the Editor Page.
I've refreshed page and even tried it on another browser (chrome and firefox on osx).

I also get the error code: Uncaught SyntaxError: Unexpected token )

Any ideas?
Thanks
Any help would be appreciated.

Replace this line with your 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:
				// Put our code here
				$('img').animate({top:"-=10px"}, 'fast');
				break;
			// Right Arrow Pressed
			case 39:
				// Put our code here
				$('img').animate({left: "-=10px"}, 'fast');
				break;
			// Down Arrow Pressed
			case 40:
				// Put our code here
				$('img').animate({top: "+=10px"}, 'fast');
				break;
		});
	});
});


#2

Hi @spookywalrus,

Your switch statement does have an opening parenthesis ((), but then it's closed immediately after on the same line, making the one on the 3rd line from the bottom throw an error since it doesn't belong :slight_smile:


#3

Aha.

Well, that particular bracket is put in there by the tutorial. I haven't touched that line of code.

I've deleted the extraneous bracket, but my little dude still doesn't work even after a refresh.
Now it gives me the error message: Uncaught SyntaxError: Unexpected token {


#4

@spookywalrus Could you post your updated code, please?


#5

You have to click the Image while pressing page down key and then while pressing page down key press up/down/left/right arrow keys to make it move.


#6

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

@black-flag:
I don't have a page down key. I'm using a mac laptop. Do you have any other suggestions (like what to use instead of a page down key?)?

Thanks


#7

@spookywalrus Wrong closing parenthesis ()).

The switch statement should look like this instead:

              // ↓ close your switch statement's condition here
switch(/* ... */) {
  // ...
}; // ← not here ;)

:slight_smile:


And you're expected to use either the , , , and keys or the W, A, S, and D keys, not Page Up or Page Down :slight_smile: