Skip to content

Commit

Permalink
Added Typing Speed Calculator (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlefiyaAbbas authored Feb 6, 2024
1 parent 3fda7a0 commit 560ad87
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Calculators/Typing-Speed-Calculator/Readme.md
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)
Binary file added Calculators/Typing-Speed-Calculator/assets/bg.jpg
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.
25 changes: 25 additions & 0 deletions Calculators/Typing-Speed-Calculator/index.html
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>
60 changes: 60 additions & 0 deletions Calculators/Typing-Speed-Calculator/script.js
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();
}
73 changes: 73 additions & 0 deletions Calculators/Typing-Speed-Calculator/style.css
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;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,20 @@ <h3>Checks the number is disarium or not and finds disarium numbers in a range.<
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Typing Speed Calculator</h2>
<h3>Calculates the typing speed in two different units.</h3>
<div class="card-footer">
<a href="./Calculators/Typing-Speed-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Typing-Speed-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
</div>

<!-- Calculator Section Ends Here -->
Expand Down

0 comments on commit 560ad87

Please sign in to comment.