Skip to content

Commit 149dedf

Browse files
Update script.js
1 parent c710ef2 commit 149dedf

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

Typing Speed Test Website/script.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const sentences = [
2-
"After all, you're only an immortal until someone manages to kill you. After that, you were just long-lived. As long as poverty, injustice and gross inequality persist in our world, none of us can truly rest.",
2+
"After all, you're only an immortal until someone manages to kill you. After that, you were just long-lived. As long as poverty, injustice and gross inequality persist in our world, none of us can truly rest.",
33

4-
"We were like deaf people trying to dance to a beat we couldn't hear, long after the music actually stopped. For once you have tasted flight you will walk the earth with your eyes turned skywards, for there you have been and there you will long to return.",
4+
"We were like deaf people trying to dance to a beat we couldn't hear, long after the music actually stopped. For once you have tasted flight you will walk the earth with your eyes turned skywards, for there you have been and there you will long to return.",
55

6-
"Time plays like an accordion in the way it can stretch out and compress itself in a thousand melodic ways. Months on end may pass blindingly in a quick series of chords, open-shut, together-apart; and then a single melancholy week may seem like a year's pining, one long unfolding note.",
6+
"Time plays like an accordion in the way it can stretch out and compress itself in a thousand melodic ways. Months on end may pass blindingly in a quick series of chords, open-shut, together-apart; and then a single melancholy week may seem like a year's pining, one long unfolding note.",
77

8-
"Life is beautiful, as long as it consumes you. When it is rushing through you, destroying you, life is gorgeous, glorious. It is when you burn a slow fire and save fuel, that life's not worth having.",
8+
"Life is beautiful, as long as it consumes you. When it is rushing through you, destroying you, life is gorgeous, glorious. It is when you burn a slow fire and save fuel, that life's not worth having.",
99

10-
"As long as people have been on this earth, the moon has been a mystery to us. Think about it. She is strong enough to pull the oceans, and when she dies away, she always comes back again. My mama used to tell me Our Lady lived on the moon and that I should dance when her face was bright and hibernate when it was dark."
10+
"As long as people have been on this earth, the moon has been a mystery to us. Think about it. She is strong enough to pull the oceans, and when she dies away, she always comes back again. My mama used to tell me Our Lady lived on the moon and that I should dance when her face was bright and hibernate when it was dark."
1111
];
1212

1313
const msg = document.getElementById('msg');
@@ -16,46 +16,46 @@ const btn = document.getElementById('btn');
1616

1717
let startTime, endTime;
1818

19-
const playGame = () =>{
20-
let randomNumber = Math.floor(Math.random()*sentences.length);
21-
msg.innerText = sentences[randomNumber];
22-
let date = new Date();
23-
startTime = date.getTime();
24-
btn.innerText = "Done";
19+
const playGame = () => {
20+
let randomNumber = Math.floor(Math.random() * sentences.length);
21+
msg.innerText = sentences[randomNumber];
22+
let date = new Date();
23+
startTime = date.getTime();
24+
btn.innerText = "Done";
2525
}
2626

27-
const endGame = ()=>{
28-
let date = new Date();
29-
endTime = date.getTime();
30-
let totalTime =0 , wordCount=0;
31-
totalTime= Math.round((endTime - startTime)/1000) // milliseconds -> 10.23 means 10 seconds 23 milliseconds
32-
console.log(totalTime);
33-
34-
let totalStr = typedWords.value;
35-
wordCount = wordCounter(totalStr);
36-
37-
let finalMsg = `You Typed Total ${wordCount} words in ${totalTime} seconds. `;
38-
msg.innerText = finalMsg;
27+
const endGame = () => {
28+
let date = new Date();
29+
endTime = date.getTime();
30+
let totalTime = 0,
31+
wordCount = 0;
32+
totalTime = Math.round((endTime - startTime) / 1000) // milliseconds -> 10.23 means 10 seconds 23 milliseconds
33+
console.log(totalTime);
34+
35+
let totalStr = typedWords.value;
36+
wordCount = wordCounter(totalStr);
37+
38+
let finalMsg = `You Typed Total ${wordCount} words in ${totalTime} seconds. `;
39+
msg.innerText = finalMsg;
3940
}
4041

4142

4243

43-
const wordCounter = (str)=>{
44-
let response = str.split(" ").length;
45-
console.log(response);
46-
return response;
44+
const wordCounter = (str) => {
45+
let response = str.split(" ").length;
46+
console.log(response);
47+
return response;
4748
}
4849

49-
btn.addEventListener('click', function(){
50-
console.log(this); // current btn
51-
if(this.innerText == 'Start'){
52-
typedWords.disabled = false;
53-
playGame();
54-
}
55-
else if(this.innerText == "Done"){
56-
typedWords.disabled = true;
57-
btn.innerText = "Start";
58-
endGame();
59-
}
50+
btn.addEventListener('click', function() {
51+
console.log(this); // current btn
52+
if (this.innerText == 'Start') {
53+
typedWords.disabled = false;
54+
playGame();
55+
} else if (this.innerText == "Done") {
56+
typedWords.disabled = true;
57+
btn.innerText = "Start";
58+
endGame();
59+
}
6060
})
6161

0 commit comments

Comments
 (0)