Open In App

Typing Game using React

Last Updated : 08 May, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

React Typing Game is a fun and interactive web application built using React. It tests and improves the user's typing speed and accuracy by presenting sentences for the user to type within a specified time limit. The game provides real-time feedback by highlighting any mistakes made by the user, making it both educational and entertaining.

A preview image of the final output:

typing game react js preview image

Prerequisite:

Approach to Create Typing Game using React

  • Display a sentence for the user to type.
  • Start a timer for the typing session.
  • Highlight mistakes in real-time by changing the background color of the incorrect word.
  • Calculate and display the user's score based on correct typings.
  • Provide a start button to initiate the typing game.
  • Allow users to select difficulty levels for sentences.
  • Display a game over message with the final score when the time runs out.

Steps to Create the React App:

Step 1: Set up a new React project using:

npx create-react-app typing-game

Step 2: Navigate to the root of the project using the following command:

cd typing-game

Project structure:

Screenshot-2024-04-26-231232

The Updated package.json will look like:

  "dependencies": {
"react": "^18.3.0",
"react-dom": "^18.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}

Example: Below is an example of creating a write typing game using React.

CSS
/* App.css */
.container {
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
    padding: 20px;
}

.title {
    font-size: 2rem;
    margin-bottom: 20px;
    color: #333;
}

.start-button {
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 10px 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin-bottom: 20px;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.start-button:hover {
    background-color: #45a049;
}

.timer {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #555;
}

.sentence {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: #333;
}

.input-container {
    margin-bottom: 20px;
}

.input-field {
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #ccc;
    transition: border-color 0.3s ease;
}

.input-field:focus {
    border-color: #4CAF50;
}

.game-over {
    font-size: 1.5rem;
    color: #f44336;
    margin-bottom: 20px;
    transition: color 0.3s ease;
}

.game-over p {
    margin: 5px 0;
}

.game-over:hover {
    color: #d32f2f;
}
JavaScript JavaScript

Start your application using the following command:

npm start

Output:


gfg73
Typing Game using React





Next Article

Similar Reads

three90RightbarBannerImg