'Filling Out the Cases' seems to be correct but doesnt work


#1



This is my code to solve the Task 'Filling Out the Cases'. Ive been told the task is solved and I can go on, but it actually does not seem to work properly.

So the problem is, that Mario is moving to the left, but I cannot move him in any of the other directions. At one time I was able to move the small window on the right but at the very moment I save and submit Mario is only to be moved to the left in Full Screen.


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

Maybe someone can explain to me whats wrong or why this is happening?!
Thanks so far.


#2

your code should be like:

case 37
{left: "-=10px"}
case 38
{top: "-=10px"}
case 39
{left: "+=10px"}
case 40
{top: "+=10px"}

any question?
@acoffeeatleast


#3

I have this but it's not working. What am I missing? TIA :slight_smile:

$(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;
}
});
});


#4

it's working
after click on save and submit button see the instruction beside Back to editor button
"Please press the required key down on [object Object]."
click on the picture

@pycoder50577


#5

It wasn't working before. It is now. Thanks!!


#6

So, got it working now!

And no further questions, it just needed some more research with your hint on my mind, but thanks.
@rcodeman


#7

I had the same problem as the OP, where my initial .animate() input code entry for case 39 looked like this:
{right: "-=10px"}

This did not result in movement, but upon changing the input code to {left: "+=10px"}, it worked.
So, OP's margin selection terminology of "up," "right," and "down" didn't seem to work.

In my case, I couldn't get "right" and "bottom" to work. ("left" and "top" worked fine.)
The case of using "right" not working took me off guard, since the hint directly references using {right: "-=10px"} as acceptable alternate code.

I did ultimately complete the exercise exclusively using "left" and "top" like in @rcodeman 's example, but being a completionist sort, it irked me a tad that I couldn't go back and use the alternative code.
So what's the appropriate identifier for altering the margin's right and bottom values?


#8

this is really helpful thanks


#9