I am trying to make a program which sees if a click is made within 2 seconds of previous click. My Code for same is:
document.addEventListener("click",do,false);
var lastBack=0;
function do(e){
if((new Date().getTime()-lastBack)<2000)
{ alert("you clicked within 2 seconds this time");}
else
{ document.write("Quickly click again");
lastBack=new Date().getTime(); }
}
I just cannot figure out whats wrong with it but when i click, it just displays 'quickly click again' and nothing else happens.Even it doesnt repeat the same line when clicked after long wait.