-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #729 from saketh-05/fixes2
Added TypingTest project
- Loading branch information
Showing
7 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Typing Test</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Typing Speed Test</h1> | ||
<div id="test-area"> | ||
<p id="text-to-type"></p> | ||
<textarea id="input-area" placeholder="Start typing..."></textarea> | ||
</div> | ||
<div id="result"> | ||
<p>Time: <span id="time">0</span> seconds</p> | ||
<p>Errors: <span id="errors">0</span></p> | ||
<p>WPM: <span id="wpm">0</span></p> | ||
<button id="reset">Restart</button> | ||
</div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Elements | ||
const textToType = document.getElementById('text-to-type'); | ||
const inputArea = document.getElementById('input-area'); | ||
const timeDisplay = document.getElementById('time'); | ||
const errorsDisplay = document.getElementById('errors'); | ||
const wpmDisplay = document.getElementById('wpm'); | ||
const resetButton = document.getElementById('reset'); | ||
|
||
// Variables | ||
let timer; | ||
let time = 0; | ||
let errors = 0; | ||
let isTyping = false; | ||
let offsetCheck = ""; | ||
|
||
const textTyping = ["The quick brown fox jumps over the lazy dog.", | ||
"A journey of a thousand miles begins with a single step.", | ||
"She sells seashells by the seashore, where the sand is soft and warm.", | ||
"The rain in Spain stays mainly in the plain, causing the fields to remain green", | ||
"To be or not to be, that is the question, pondered the thoughtful philosopher.", | ||
"In the middle of difficulty lies opportunity, waiting for those who seek it.", | ||
"The early bird catches the worm, but the second mouse gets the cheese.", | ||
"Beneath the stars, the vast ocean whispered secrets to the moonlit sky.", | ||
"Innovation distinguishes between a leader and a follower in every industry.", | ||
"The beauty of the world lies in the diversity of its people and cultures." | ||
]; | ||
|
||
const randomIndexText = () => { | ||
const rIndex = Math.floor(Math.random() * (10)); | ||
textToType.innerText = offsetCheck = textTyping[rIndex]; | ||
}; | ||
|
||
document.addEventListener("DOMContentLoaded",() => { | ||
randomIndexText(); | ||
}); | ||
|
||
// Functions | ||
function startTimer() { | ||
timer = setInterval(() => { | ||
time++; | ||
timeDisplay.innerText = time; | ||
}, 1000); | ||
} | ||
|
||
function stopTimer() { | ||
clearInterval(timer); | ||
} | ||
|
||
function calculateWPM() { | ||
const wordsTyped = inputArea.value.trim().split(' ').length; | ||
const wpm = Math.round((wordsTyped / time) * 60); | ||
return wpm; | ||
} | ||
|
||
function resetTest() { | ||
stopTimer(); | ||
time = 0; | ||
errors = 0; | ||
isTyping = false; | ||
inputArea.value = ''; | ||
timeDisplay.innerText = time; | ||
errorsDisplay.innerText = errors; | ||
wpmDisplay.innerText = 0; | ||
inputArea.disabled = false; | ||
randomIndexText(); | ||
inputArea.focus(); | ||
} | ||
|
||
// Event Listeners | ||
inputArea.addEventListener('input', () => { | ||
if (!isTyping) { | ||
isTyping = true; | ||
startTimer(); | ||
} | ||
|
||
const typedText = inputArea.value; | ||
const typedTextLength = typedText.length; | ||
|
||
if (typedText === offsetCheck) { | ||
stopTimer(); | ||
inputArea.disabled = true; | ||
wpmDisplay.innerText = calculateWPM(); | ||
} | ||
|
||
if (typedTextLength > 0) { | ||
if (typedText[typedTextLength - 1] !== offsetCheck[typedTextLength - 1]) { | ||
errors++; | ||
errorsDisplay.innerText = errors; | ||
} | ||
} | ||
}); | ||
|
||
resetButton.addEventListener('click', resetTest); | ||
|
||
// Initialize | ||
resetTest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f8b7b7; | ||
color: #333; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
} | ||
|
||
.container { | ||
text-align: center; | ||
background-color: white; | ||
padding: 30px; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
width: 600px; | ||
height: auto; | ||
} | ||
|
||
h1 { | ||
margin-bottom: 20px; | ||
} | ||
|
||
#test-area { | ||
margin-bottom: 20px; | ||
} | ||
|
||
#text-to-type { | ||
font-size: 18px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
#input-area { | ||
width: 100%; | ||
height: 100px; | ||
padding: 10px; | ||
font-size: 16px; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
} | ||
|
||
#result { | ||
font-size: 16px; | ||
} | ||
|
||
#result p { | ||
margin: 5px 0; | ||
} | ||
|
||
#reset { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
margin-top: 10px; | ||
cursor: pointer; | ||
border: none; | ||
background-color: #007bff; | ||
color: white; | ||
border-radius: 4px; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.