/    Sign up×
Community /Pin to ProfileBookmark

Timing Delay Between Two Actions

Hi, I am new to javascript and trying to teach myself it. I am trying to make a little script that tells a user their reaction time. I want to change the background color of the page, and see how long it takes for them to click down.

I can’t seem to find a suitable way to time this accurately. First, I tried making a setInterval call that would increment a value every ms. However, apparently it is not fast enough to do this, and the values it reports are far too low.

Then I tried calling the date.getTime() function when the background changes color, and comparing it to the time when the user clicks, but both values are exactly the same so it always outputs 0.

Is there a way to accurately time this?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Wisest_GuyMar 09.2008 — [CODE]var BeginTime;

function TheStartingClick(){
BeginTime = Date.now();
}

function TheFinishClick(){
var elapsedTime = Date.now() - BeginTime;
}[/CODE]
×

Success!

Help @Jforsyth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...