+ 3

[SOLVED] movingBox

How to make the "Stop" button work? https://code.sololearn.com/Wrm1sxugCpsp/#

12th Dec 2018, 8:24 PM
evgeniy_pp
evgeniy_pp - avatar
9 Antworten
+ 4
Just 2 corrections in js code, In line 14 button1.onclick = stop; In line 57 button.onclick = start; Notes: - when calling the functions from js part then they should nt be in double quotes - since the functions "start" and "stop" are already defined, so to call them using event (onclick), we do not need the function call parentheses ( )
12th Dec 2018, 8:45 PM
Morpheus
Morpheus - avatar
+ 5
evgeniy_pp, no probs, 😀 By adding these 2 lines inside stop function on top at line 48, we can reset the position to initial position. box.style.left = "0px"; box.style.top = "0px";
12th Dec 2018, 9:29 PM
Morpheus
Morpheus - avatar
+ 4
evgeniy_pp Just copy line 2 to 5, on to the top of the code. var pos = 0; //for moving right var pos1 = 0; //for moving down var pos2 = 490; //for moving left var pos3 = 290; //for moving up I leave the reasoning behind this to you, but the clue is "function scopes" and "global scopes"
12th Dec 2018, 9:06 PM
Morpheus
Morpheus - avatar
+ 3
Tried to do some 'rework' on the code... https://code.sololearn.com/W12hvL3uMTLo/?ref=app
12th Dec 2018, 10:18 PM
KraBBy
KraBBy - avatar
+ 3
hint: I'm learning Js just like you, so there is no warranty ;-)
12th Dec 2018, 10:35 PM
KraBBy
KraBBy - avatar
+ 1
Morpheus, thank you. I tried to delete quotes but did not think about parentheses. Actually, now I have a new problem XD The box does not reset correctly if it's in right, bottom or left corners. Check the code, please. I understand why it's happening but do not have a solution yet. I'm gonna to figure it out.
12th Dec 2018, 9:01 PM
evgeniy_pp
evgeniy_pp - avatar
+ 1
Morpheus Got it. Thank you again. Just little curiosity: is it possible to make the box to return to starting position after pressing "Stop" using this code or I have to rewrite it completely to do this?
12th Dec 2018, 9:25 PM
evgeniy_pp
evgeniy_pp - avatar
+ 1
Morpheus I must already start to figure out things like that by myself 😅
12th Dec 2018, 9:32 PM
evgeniy_pp
evgeniy_pp - avatar
0
KraBBy I will look at it later, thank you. Good job, it really works now
12th Dec 2018, 10:21 PM
evgeniy_pp
evgeniy_pp - avatar