Mini project
Typing Speed Test with JavaScript
A browser typing test that shows a passage, highlights each character as you type, and calculates words per minute and accuracy live, with a timer and saved best scores.
HTMLCSSJavaScriptlocalStorage
The problem
Typing speed matters for coding, exams and office work, and a typing test is a fun way to practise. This project shows a passage, checks every key you press, and measures your speed and accuracy as you go — all in the browser, with no server.
Features to build
- Show a random passage and highlight each character green (correct) or red (wrong) as you type
- Start the timer on the first key press, with 30, 60 and 120 second modes
- Live words per minute (WPM) and accuracy while typing
- Backspace to fix mistakes, with corrected errors still counted in accuracy
- A result screen with WPM, accuracy, and the characters you missed most
- Save the best score for each mode with localStorage
- Works with the keyboard only, and on mobile screens
Build plan
- 1
Lay out the page
Put the passage in a block of <span> elements, one per character, so each can be coloured separately. Add the timer, WPM and accuracy display above it.
- 2
Capture typing
Listen to the input event on a hidden text field, so typing works on phones too, and compare the typed text with the passage character by character.
- 3
Run the timer
Start on the first key, store the start time with performance.now(), and update the display every 100 ms with setInterval until time runs out.
- 4
Calculate the scores
WPM is correct characters divided by 5, divided by the minutes elapsed. Accuracy is correct key presses divided by all key presses.
- 5
Finish and save
Stop the test, show the result screen, and keep the best WPM for each mode in localStorage.
Learn these first
Each part of the project is taught in one of these free lessons.
- Introduction to the DOM: How JavaScript Sees and Changes Web Pages
- JavaScript Events: addEventListener, the Event Object and Common Events
- JavaScript Strings: Template Literals, Methods, Slicing and Searching
- JavaScript Arrays: Creating, Accessing, Adding and Removing Items
- localStorage and sessionStorage in JavaScript: Saving Data in the Browser
- CSS Transitions: Smooth Hover Effects with transition-duration and Timing Functions
- Responsive Web Design: Fluid Layouts, Mobile First and Flexible Images
Make it stand out
- A chart of WPM over the test, sampled every second
- Practice mode that repeats your most-missed characters
- Passages in code (JavaScript or Python) for programmers
- A shareable result card image made with the canvas
Viva and interview questions
Try to answer each one aloud before you open it.
How do you calculate words per minute?
By convention a word is 5 characters, including spaces. WPM = (correct characters ÷ 5) ÷ minutes elapsed. Using a fixed 5 characters makes scores comparable across passages with short and long words.
Why use performance.now() instead of Date.now() for the timer?
performance.now() is a high-resolution clock that only moves forward, so changing the computer's clock during a test cannot affect it. Date.now() follows the system clock, which can jump.
Why listen to the input event instead of keydown?
On phones, many on-screen keyboards do not send reliable keydown events, and features like autocorrect change text without key presses. The input event fires whenever the field's text changes, whatever caused it.
How would you stop someone from pasting the passage?
Listen for the paste event and call preventDefault(), and also check that the typed text grows by about one character per event. Large jumps mean text was inserted at once.
What to put in your project report
- Abstract: the problem, your solution and the result in one paragraph.
- Introduction and problem statement: who has the problem and why it matters.
- Requirements: the features (functional) and qualities such as speed and security (non-functional).
- Design: architecture diagram, database tables or data flow, and screen layouts.
- Implementation: the main modules and the most interesting code, explained.
- Testing: the test cases you ran, with inputs, expected and actual results.
- Results: screenshots or numbers that show the project working.
- Conclusion and future scope: what you achieved and what you would add next.
Your college may give its own format. Follow that first, and use this list to check nothing is missing.
More project ideas
- Personal Portfolio Website with HTML and CSSMini project
- Quiz App with HTML, CSS and JavaScriptMini project
- Snake Game with JavaScript and CanvasMini project