Click Button | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Click Button

I cant tell if this is working or not. what i mena is are my clicks working? I have a function for the same button but theyre are for different uses. Anyone know of anythinng is wrong with the code or am i paranoid i cant click my own button? https://code.sololearn.com/W2FE8G5Sh5MZ/?ref=app

2nd Jun 2022, 8:57 PM
Junior
Junior - avatar
26 Answers
+ 3
You put the setInterval line inside the definition of the move function. Move it outside of it and remove the extra call to move that comes directly after and it works.
3rd Jun 2022, 12:54 AM
Simon Sauter
Simon Sauter - avatar
+ 1
Isn't it by design that you can't click the button? The moment the mouse cursor moves over the button the button jumps away, so of course you can't click it. However, on mobile, sometimes the button stops moving around and when that happens you can click it and the counter works.
2nd Jun 2022, 9:18 PM
Simon Sauter
Simon Sauter - avatar
+ 1
so should i add a transition to make it clickible?
2nd Jun 2022, 9:20 PM
Junior
Junior - avatar
+ 1
It depends on what your goal is. But if you want people to be able to click the button it can't move away before they have the chance to click it.
2nd Jun 2022, 9:22 PM
Simon Sauter
Simon Sauter - avatar
0
Why don't you just use the click event instead of mouse over? You can attach multiple function to an element/ event
2nd Jun 2022, 9:22 PM
Lisa
Lisa - avatar
0
so should i reorganize my javascript so you can click it first before ot moves?
2nd Jun 2022, 9:23 PM
Junior
Junior - avatar
0
You could use click events for both. Just make sure that you add clicker() before move() to the button
2nd Jun 2022, 9:26 PM
Lisa
Lisa - avatar
0
In case you are trying to do a game of catching the button, shouldn't the moving be primarily independent of the user's response? Like the button changing its position at random intervals when the player doesn't catch it?
2nd Jun 2022, 10:19 PM
Lisa
Lisa - avatar
0
hmm could work…good idea i can do that
2nd Jun 2022, 10:35 PM
Junior
Junior - avatar
0
okay, so im trying to make the button move while you have to try to click it but its not moving https://code.sololearn.com/WZiF88n1IQ2I/?ref=app
2nd Jun 2022, 10:56 PM
Junior
Junior - avatar
0
It does move. But just once at the start.
2nd Jun 2022, 11:18 PM
Simon Sauter
Simon Sauter - avatar
0
ye so how do i make it move infinetly? I used setInterval abd used math.random but its not working
2nd Jun 2022, 11:19 PM
Junior
Junior - avatar
0
Use a loop?
2nd Jun 2022, 11:20 PM
Simon Sauter
Simon Sauter - avatar
0
like a while loop?
2nd Jun 2022, 11:21 PM
Junior
Junior - avatar
0
Okay, I used a while loop but now nothings working. very confusing https://code.sololearn.com/WZiF88n1IQ2I/?ref=app
2nd Jun 2022, 11:23 PM
Junior
Junior - avatar
0
Your condition makes no sense. I'd try using an infinite loop using true as condition. But I don't have much experience with Javascript, so I'm not sure if that will work.
2nd Jun 2022, 11:25 PM
Simon Sauter
Simon Sauter - avatar
0
uhh..k so can u show me what im doing wrong and what type of loop i should be using
2nd Jun 2022, 11:27 PM
Junior
Junior - avatar
2nd Jun 2022, 11:28 PM
Junior
Junior - avatar
0
The original code interacts differently in a web browser opposed to this app. Have you tried it on desktop? To see the differences?
2nd Jun 2022, 11:37 PM
Chris Coder
Chris Coder - avatar
0
ye ye but i wanted the button to move infinetly while u chase it. thats why i sdded a setInterval so it moves every second
3rd Jun 2022, 12:14 AM
Junior
Junior - avatar