0
Can anyone can help me to move the circle in the below link by clicking on the button?
7 Respuestas
+ 4
Here is the correct (re-written) code :
https://code.sololearn.com/WXydOMAd5Aa2/?ref=app
+ 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);
+ 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
+ 1
const goUp = () => y--;
up.onclick = goUp;
Can you please explain me the meaning of "()=>y--"
+ 1
Thank both of you because today I learn 2 new things
0
Thank you
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