0

Why does this code not work properly?

I tried to manipulate the code from Sololearn, so that the box not just goes to the right. Why moves it just to the right and left and not down and up? What fo I have to fix? https://code.sololearn.com/W186hKm6aj9d/?ref=app

5th Aug 2017, 9:43 AM
Raphael Burkardt
Raphael Burkardt - avatar
6 Respostas
+ 5
Your mistake is in these lines: box.style.top = posy+'py'; The string at end of the property value is the css unit you want to append to the numerical value... and there's no 'py' css unit, just 'px', which stand for 'pixels' ;P (you need to correct it in both function using 'top' css style attribute ^^)
5th Aug 2017, 10:01 AM
visph
visph - avatar
+ 4
You only invoke the function movex... So in the interval t you should use this: var t = setInterval(function() { movex(); movey(); }, 10); O and px is a unit, it stands for pixel so change the part with py back to px and it should work
5th Aug 2017, 10:01 AM
The Coding Sloth
The Coding Sloth - avatar
+ 4
@The Coding Sloth: The setInterval() method is correctly used in this code, if the purpose is to chain the four moves one after each other ;)
5th Aug 2017, 10:05 AM
visph
visph - avatar
+ 4
I had no doubt on that :D
5th Aug 2017, 10:08 AM
visph
visph - avatar
+ 1
Ok thanks I thought px stands for "position of x" and forgot the "".
5th Aug 2017, 10:05 AM
Raphael Burkardt
Raphael Burkardt - avatar
0
Now it works.
5th Aug 2017, 10:07 AM
Raphael Burkardt
Raphael Burkardt - avatar