Ask coding questions

← Back to all posts
Help with JS
PYTHORE3605 (138)

I am teaching myself .js and i decided to make a basic clicker and I don't understand why the idle button isn't working. Sorry if the code is sloppy i don't know much .js

Answered by AloegelhiPlaysR (131) [earned 5 cycles]
View Answer
AloegelhiPlaysR (131)

If you want to add 1 var every second the button is clicked you can do this:

let add_one = setInterval(function() { 
num += 1
}, 1000)

Replace num with the name of your var.

Now, To make it stop, you can use

ch1ck3n (2022)

Well i don't want to feed you the answer but here's my approach:

function idle(){
 timeran = 0
 var addone = setInterval(function(){if (timeran<100){time()}else{clearInterval(addone)}}, 1000)
ch1ck3n (2022)

@PYTHORE3605 but whaaaaa the other guy got it

PYTHORE3605 (138)

@ch1ck3n srry but he answered first. maybe next time.

PYTHORE3605 (138)

@ch1ck3n not what mine says but okay. if i have another question ill ask u

ch1ck3n (2022)

what is the idle button supposed to do

PYTHORE3605 (138)

@ch1ck3n add 1 to var every second