-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Typing Speed Calculator (#551)
- Loading branch information
1 parent
3fda7a0
commit 560ad87
Showing
7 changed files
with
188 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# <p align="center">Typing Speed Calculator</p> | ||
|
||
## Description :- | ||
|
||
A typing speed calculator that calculates the typing speed in two different units: <br/> | ||
i) words/sec and <br/> | ||
ii) characters/sec | ||
|
||
## Tech Stack :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots :- | ||
![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/dc4f9d88-cd93-40b6-a0be-f93210bc54ab) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 Speed Test</title> | ||
<link rel="stylesheet" href="style.css"> | ||
<script src="script.js"></script> | ||
</head> | ||
|
||
<body onload="getRandomSentence()"> | ||
<h1>Typing Speed Test</h1> | ||
<div id="typing-box"> | ||
<p>Type the following text:</p> | ||
<p id="text-to-type"></p> | ||
<div class="form-wrapper"> | ||
<input type="text" id="user-input" oninput="checkInput()" onpaste="return false;"> | ||
<button onclick="resetInput()">Reset</button> | ||
</div> | ||
<p id="speed-result"></p> | ||
</div> | ||
</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,60 @@ | ||
let startTime; | ||
let endTime; | ||
let typedText = ''; | ||
const sentences = [ | ||
'The quick brown fox jumps over the lazy dog', | ||
'The five boxing wizards jump quickly', | ||
'Pack my box with five dozen milk jugs', | ||
'How jumping frogs can level six piqued gymnasts', | ||
'The quick onyx goblin jumps over the lazy dwarf', | ||
]; | ||
|
||
|
||
function getRandomSentence() { | ||
let randomIndex = Math.floor(Math.random() * sentences.length); | ||
document.getElementById('text-to-type').textContent = sentences[randomIndex]; | ||
} | ||
|
||
function startTimer() { | ||
startTime = new Date(); | ||
} | ||
|
||
function stopTimer() { | ||
endTime = new Date(); | ||
calculateSpeed(); | ||
} | ||
|
||
function checkInput() { | ||
if (!startTime) { | ||
startTimer(); | ||
} | ||
typedText = document.getElementById('user-input').value; | ||
let textToType = document.getElementById('text-to-type').textContent; | ||
if (typedText === textToType) { | ||
stopTimer(); | ||
} | ||
} | ||
|
||
function calculateSpeed() { | ||
let elapsedTime = (endTime - startTime) / 1000; // Convert to seconds | ||
let words = typedText.trim().split(/\s+/).length; | ||
let characters = typedText.length; | ||
let wordsPerSec = words / elapsedTime; | ||
let charactersPerSec = characters / elapsedTime; | ||
displaySpeed(wordsPerSec, charactersPerSec); | ||
} | ||
|
||
function displaySpeed(wordsPerSec, charactersPerSec) { | ||
let resultElement = document.getElementById('speed-result'); | ||
resultElement.innerHTML = `Your typing speed is: i) ${wordsPerSec.toFixed(2)} words/sec | ||
ii) ${charactersPerSec.toFixed(2)} characters/sec.`; | ||
} | ||
|
||
function resetInput() { | ||
document.getElementById('user-input').value = ''; | ||
document.getElementById('speed-result').innerHTML = ''; | ||
startTime = null; | ||
endTime = null; | ||
typedText = ''; | ||
getRandomSentence(); | ||
} |
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,73 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=ABeeZee&display=swap'); | ||
|
||
body { | ||
font-family: 'ABeeZee', sans-serif; | ||
background-color: #f4f4f4; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
background-image: url('./assets/bg.jpg'); | ||
background-position: 30% 30%; | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
} | ||
h1{ | ||
color: #fff; | ||
text-align: center; | ||
font-size: 3rem; | ||
margin-bottom: 20px; | ||
|
||
} | ||
#typing-box { | ||
background-color: #fff; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
padding: 20px; | ||
max-width: 500px; | ||
width: 100%; | ||
text-align: center; | ||
} | ||
|
||
#text-to-type { | ||
font-size: 18px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
#user-input { | ||
padding: 10px; | ||
margin-bottom: 20px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
font-size: 16px; | ||
text-align: center; | ||
} | ||
|
||
button { | ||
background-color: #19238d; | ||
color: white; | ||
padding: 10px 20px; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
transition: background-color 0.3s ease; | ||
} | ||
|
||
button:hover { | ||
background-color: #19238d; | ||
} | ||
|
||
#speed-result { | ||
font-size: 16px; | ||
margin-top: 20px; | ||
} | ||
|
||
.form-wrapper{ | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} |
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