Typing Speed Detector App Using Typescript (original) (raw)

Last Updated : 05 Feb, 2025

Typing speed has been a very important test for Engineers as a faster typing skill leads to faster code so, To test this speed we are building a typing speed detector.

What We’re Going to Create

Project Preview

Screenshot-2025-01-28-113816

Typing speed detector using Typescript

Typing Speed Detector - HTML and CSS code

This is a Typing Speed Test web app where users can measure their typing speed in Words Per Minute (WPM). It includes a timer, input area, and a start button to begin the test.

HTML `

Typing Speed Test

Press Start to begin typing

Time: 0s

WPM: 0

Start

`

**In this Example

Typing Speed Detector - Typescript logic

This code creates a dynamic grid that allows users to draw on it by changing the grid size and color. It supports interaction with mouse events for drawing and resetting the grid.

Typing.ts `

const c = document.querySelector(".container"); const s = document.querySelector('.size'); const col = document.querySelector('.color'); const rBtn = document.querySelector('.button');

if (!c || !s || !col || !rBtn) { throw new Error("Missing required DOM elements"); }

let sz: number = parseInt(s.value); let d: boolean = false;

function g(): void { c.style.setProperty("--size", sz.toString()); c.innerHTML = "";

for (let i = 0; i < sz * sz; i++) {
    const b = document.createElement("div");
    b.classList.add("box");
    b.addEventListener('mouseenter', () => o(b));
    b.addEventListener('mousedown', () => m(b));
    c.appendChild(b);
}

}

function o(b: HTMLDivElement): void { if (!d) return; b.style.backgroundColor = col.value; }

function m(b: HTMLDivElement): void { b.style.backgroundColor = col.value; }

window.addEventListener('mousedown', () => { d = true; });

window.addEventListener('mouseup', () => { d = false; });

function r(): void { g(); }

rBtn.addEventListener('click', r);

s.addEventListener('change', () => { sz = parseInt(s.value); r(); });

g();

`

**In this example

Convert to JavaScript File

Now You need to convert the TypeScript file into JavaScript to render by browser. Use one of the following command.

npx tsc typing.ts
tsc typing.ts

Complete Code

HTML ``

Typing Speed Test

Press Start to begin typing

Time: 0s

WPM: 0

Start