Mario move - not working


There is a task where, moving MARIO image to left is already working. I am adding the code to move it to remaining directions, but its not working out for me. Please suggest.

this code is given and working
// Left arrow key pressed
case 37:
$('img').animate({left: "-=10px"}, 'fast');

this is the code i did for other moves

		// Up Arrow Pressed
		case 38:
			$('img').animate({up: "-=10px"}, 'fast');
		// Right Arrow Pressed
		case 39:
			$('img').animate({right: "-=10px"}, 'fast');
		// Down Arrow Pressed
		case 40:
			$('img').animate({down: "-=10px"}, 'fast');


you need to use left and top


I don't know whether you get the explanation that came before me or not so I will try to make it simpler. The left zainabrawat referred to is the left margin. By putting in the code ({left: "-=10px"}, "fast") You are telling the computer to reduce the left margin by ten, effectively moving the img to the left. The same goes for top. You can't do this for right or bottom though. To substitute for that, you must put in this code to move right ({left: "+=10px"}, "fast"). This tells the computer to increase the margin on the left, effectively moving it to the right. The following code will move your img down for the same reason ({top: "+=10px"}, "fast")


oh yes !! sorry guys, i totally forgot we're dealing with the margin here :neutral_face: anyways thanks for the help @astrosloth1 @zainabrawat


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