A typing speed test shows a sentence, times how fast you type it, and reports your words per minute and accuracy. It is a fun project that teaches you timers, keyboard events, and comparing two strings character by character.

What you are building

A random sentence appears on screen. Click start, type it in the box below, and when you finish the app shows your speed in words per minute (WPM), your accuracy, and the time taken. A new sentence button lets you try again.

The HTML structure

<p id="sentence"></p> <textarea id="input" rows="3" placeholder="Start typing here..."></textarea> <p>Time: <span id="time">0</span>s</p> <p>WPM: <span id="wpm">0</span></p> <p>Accuracy: <span id="accuracy">100</span>%</p> <button id="new-sentence">New Sentence</button> 

Picking a sentence and starting the timer

Keep a small list of sentences and start the clock on the first keystroke:

const sentences = [ "The quick brown fox jumps over the lazy dog.", "Practice makes perfect when you type every day.", "JavaScript is fun to learn by building small projects.", ]; let startTime = null; let currentSentence = ""; function newSentence() { currentSentence = sentences[Math.floor(Math.random() * sentences.length)]; document.getElementById("sentence").textContent = currentSentence; document.getElementById("input").value = ""; startTime = null; } document.getElementById("input").addEventListener("input", (event) => { if (startTime === null) startTime = Date.now(); const typed = event.target.value; const elapsedMinutes = (Date.now() - startTime) / 60000; if (typed === currentSentence) { const words = currentSentence.split(" ").length; const wpm = Math.round(words / elapsedMinutes); document.getElementById("wpm").textContent = wpm; } }); 

Calculating accuracy

Compare the typed text with the target, character by character, and count the matches:

function calculateAccuracy(typed, target) { let correct = 0; for (let i = 0; i < typed.length; i++) { if (typed[i] === target[i]) correct++; } return Math.round((correct / target.length) * 100); } 

Update the accuracy display on every keystroke, and colour the sentence — green for correct characters, red for mistakes — so the user sees errors as they type.

What to add next

Save the best WPM in localStorage, add difficulty levels with longer sentences, or highlight the current word instead of the whole sentence. A live per-character colour display is the feature that makes it feel like a real typing app.