-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyScripts.js
More file actions
63 lines (47 loc) · 1.8 KB
/
Copy pathmyScripts.js
File metadata and controls
63 lines (47 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
window.onload= function(){
var startTime= new Date().getTime();
var endTime = null,timeTaken,bestTime=1000000;
var shapeElement = document.getElementById("shape");
var buttonElement= document.getElementById("startButton");
buttonElement.onclick= function(){
if(buttonElement.innerHTML==="Let's Start"){
buttonElement.innerHTML="Finish!";
makeShapeAppear();
}else{
buttonElement.innerHTML="Let's Start";
document.getElementById("displayTime").innerHTML= "0.00 sec";
shapeElement.style.display="none";
alert("Thanks for playing! \n Your best reaction time is :"+bestTime+" seconds!\n Keep it up *_*" );
bestTime = 1000000;
}
}
shapeElement.onclick= function(){
endTime= new Date().getTime();
timeTaken= (endTime- startTime)/1000;
if(timeTaken<bestTime)
bestTime=timeTaken;
shapeElement.style.display="none";
document.getElementById("displayTime").innerHTML= timeTaken+"sec";
setTimeout(function(){
startTime=new Date().getTime();
makeShapeAppear();
},
700 );
}
function makeShapeAppear(){
shapeElement.style.backgroundColor="white";
var shapes=["circle","square","rectangle","parallelogram","triangle-left","triangle-right","trapezoid","triangle-up","triangle-down"];
var sIndex= Math.floor(Math.random()*9);
var colors=["red","yellow","pink","violet","black","brown","purple","cyan","blue","green","orange","indigo"];
var cIndex=Math.floor(Math.random()*12);
var startLeft= Math.floor(Math.random()*800+100);
var startTop= Math.floor(Math.random()*100+200);
shapeElement.className= shapes[sIndex];
if(sIndex<4)
shapeElement.style.backgroundColor=colors[cIndex];
shapeElement.style.left=startLeft+"px"
//alert(shapeElement.style.left);
shapeElement.style.top= startTop+'px';
shapeElement.style.display="block";
}
};