0

Can anyone can help me to move the circle in the below link by clicking on the button?

https://code.sololearn.com/WzGFws9iX1e8/?ref=app

1st Jun 2020, 3:31 PM
Omkar Kamat
Omkar Kamat - avatar
7 Respuestas
+ 4
Here is the correct (re-written) code : https://code.sololearn.com/WXydOMAd5Aa2/?ref=app
1st Jun 2020, 4:04 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 4
ok ok It’s very simple :D I used ES6 to write it in a more fancy way. It is as same as : function goUp() { return y--; // same as y = y - 1; // which means we are decreasing // 'y' by 1 in each frame } const up = document.getElementById('up'); up.addEventListener('click', goUp);
1st Jun 2020, 4:20 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
ok ok First problem you can't write ++1 or 1++. It will give error. You should write x++ or ++x. 2nd problem you can't create one function inside another function. You can only call function into another function. Create UP function outside the game function. 3rd problem you can't access local variable inside another function. You need to make it global. Make x and y variable global. https://code.sololearn.com/W8hzc6e223Fq/?ref=app
1st Jun 2020, 4:02 PM
A͢J
A͢J - avatar
+ 1
const goUp = () => y--; up.onclick = goUp; Can you please explain me the meaning of "()=>y--"
1st Jun 2020, 4:18 PM
Omkar Kamat
Omkar Kamat - avatar
+ 1
Thank both of you because today I learn 2 new things
1st Jun 2020, 4:19 PM
Omkar Kamat
Omkar Kamat - avatar
0
Thank you
1st Jun 2020, 4:25 PM
Omkar Kamat
Omkar Kamat - avatar
0
You can use a closure as an alternative, but you will have to create at least one function inside of the game function. https://code.sololearn.com/WcZm7fHWoafr/#html
1st Jun 2020, 5:09 PM
ODLNT
ODLNT - avatar