var w,h,g,el,my={} function reactionMain(){this.version='0.88';w=500;h=500;clrs=["red","yellow"];this.MAX=5;this.count=0;this.times=[];var s='';s+='
';s+='';sttStr='You will see a circle ... wait until it changes color and click anywhere on the screen as quickly as you can.

Your speed will be recorded over '+this.MAX+' attempts and your average shown.

Click now to play.';s+='
'+sttStr+'
';endStr='You may find the last score, when the dot flashed up big, was your quickest reaction time.
This means that the rest of the time you were not using your "startle" reflex to react quickly.';s+='
';s+='
';s+='
';s+='';s+='
© 2016 MathsIsFun.com v'+this.version+'
';s+='
';document.write(s);el=document.getElementById('canvasId');ratio=2;el.width=w*ratio;el.height=h*ratio;el.style.width=w+"px";el.style.height=h+"px";g=el.getContext("2d");g.setTransform(ratio,0,0,ratio,0,0);status='stt';} var sttTime;var timeID;function circSize(d){var div=document.getElementById('circle');div.style.left=(((w-d)/2)<<0)+'px';div.style.top=(((w-d)/2)<<0)+'px';div.style.width=(d<<0)+'px';div.style.height=(d<<0)+'px';div.style.borderRadius=((d/2)<<0)+'px';} function makecircle(){circSize(40);var time=Math.random();time=1500+time*2500;timeID=setTimeout(function(){document.getElementById('circle').style.backgroundColor=clrs[1];if(this.times.length==this.MAX-1){circSize(w*1);} status='on';sttTime=performance.now();},time);} function restart(){status='stt';doClick();} function doClick(){switch(status){case 'stt':circSize(40);document.getElementById("circle").style.backgroundColor=clrs[0];document.getElementById('circle').style.opacity=1;document.getElementById('instr').style.left='-999px';document.getElementById('instr').style.opacity=0;document.getElementById('restart').style.opacity=0;document.getElementById('result').innerHTML='';g.clearRect(0,0,el.width,el.height);times=[];status='wait';makecircle();break;case 'wait':document.getElementById("result").innerHTML="Not Yet";clearTimeout(timeID);makecircle();break;case 'on':var clickTime=performance.now();elapsed=(clickTime-sttTime)/1000;if(elapsed<0.1){status='wait';document.getElementById("result").innerHTML="Not Yet";clearTimeout(timeID);makecircle();}else{times.push(elapsed);drawRTs();doResult();} document.getElementById("circle").style.backgroundColor=clrs[0];status='wait';if(times.length0)s+=', ';s+=fmt3(this.times[i])+'s';sum+=this.times[i];} var avg=sum/this.times.length;if(simpleQ)return s;s='';var simpleAvg=avg;do{var prev=avg;avg=calcMean(prev*1.6);}while(Math.abs(avg-prev)>0.001);if(Math.abs(avg-simpleAvg)<0.001){s+='Average: '+fmt3(simpleAvg)+' sec';}else{s+='Average (with outliers): '+fmt3(simpleAvg)+' sec';s+='
Average (no outliers): '+fmt3(avg)+' sec';} var descr='';if(avg<0.22){descr='That was super fast!';}else if(avg<0.26){descr='That was very fast!';}else if(avg<0.30){descr='That was fast.';}else if(avg<0.34){descr='Well done';}else if(avg<0.38){descr='';}else{descr='';} s+='
'+descr;s+='

'+endStr;return s;} function calcMean(out){var sum=0;var n=0;for(i=0;i