forked from connieDeng/typingGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
141 lines (124 loc) · 2.75 KB
/
functions.js
File metadata and controls
141 lines (124 loc) · 2.75 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function initialize()
{
userInput = document.getElementById("input");
Wpm = document.getElementById("wpm");
textBox = document.getElementById("text");
text0=document.getElementById("aabbcc");
text1=document.getElementById("Torque");
text2=document.getElementById("WW1");
text3=document.getElementById("NASAJourneyToMars");
text4=document.getElementById("HistoryOfTokyo");
text5=document.getElementById("DigitalExplosion");
textBox.innerHTML = "Choose which text you would like to type!";
startTime = 60;
TIME = startTime;
timeLeft = document.getElementById("time");
timeLeft.innerHTML = "Time left: " + startTime;
activated = false;
wordsTyped=[];
Length=0;
Sec30 = document.getElementById("sec30");
Sec60 = document.getElementById("sec60");
Sec90 = document.getElementById("sec90");
userInput.disabled = true;
text0.disabled = false;
text1.disabled = false;
text2.disabled = false;
text3.disabled = false;
text4.disabled = false;
text5.disabled = false;
Sec30.disabled = false;
Sec60.disabled = false;
Sec90.disabled = false;
}
function clock(){
if (activated === false){
activated = true;
Sec30.disabled = true;
Sec60.disabled = true;
Sec90.disabled = true;
text0.disabled = true;
text1.disabled = true;
text2.disabled = true;
text3.disabled = true;
text4.disabled = true;
text5.disabled = true;
time = setInterval(function()
{
startTime--;
timeLeft.innerHTML = "Time left: " + startTime;
if(startTime <= 0)
{
clearInterval(time);
userInput.disabled = true;
WPMCalcuation();
}
},1000);
}
}
function valid()
{
firstWord = sentence[0];
if(firstWord==userInput.value)
{
correctWords();
return true;
}
else
{
return false;
}
}
function correctWords()
{
wordsTyped.push(firstWord + " ");
}
function deleteFirst()
{
sentence.shift();
newSentence = "";
for (var i = 0; i < sentence.length; i++)
{
newSentence = newSentence + " " + sentence[i];
textBox.innerHTML = newSentence;
}
}
window.onkeypress = function(event)
{
var space = event.keyCode;
if (space == 32)
{
event.preventDefault();
continueOn();
}
}
function continueOn()
{
if (valid()===true)
{
deleteFirst();
userInput.value ="";
}
}
function WPMCalcuation()
{
for (var i = 0; i < wordsTyped.length; i++)
{
Length = Length + wordsTyped[i].length;
}
Wpm.innerHTML = "Your WPM: " + Math.round((Length/6)/(TIME/60));
}
function changeTime(seconds)
{
startTime = seconds;
timeLeft.innerHTML = "Time left: " + startTime;
TIME = startTime;
}
function restart()
{
initialize();
userInput.value = "";
Sec90.disabled = false;
clearInterval(time);
Wpm.innerHTML = "WPM";
}