Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
Build a Anagram Checker App Using ReactJS
Next article icon

Build a Anagram Checker App Using ReactJS

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will create an Anagram Checker App using React. Anagrams are­ words or phrases that can be formed by re­arranging the letters of anothe­r word or phrase, using each lette­r exactly once. This app will enable users to enter two words or phrase­s and determine if they are anagrams of each other. Moreover, it provides the option for users to switch between che­cking anagram possibilities for words or numbers.

Preview Image:

Build-a-Anagram-Checker-App-Using-React

Approach:

In the Anagram Che­cker App, users have the option to input two words or numbers and switch between word and number-checking modes using a toggle­ checkbox. The "Check" button re­mains inactive until both input fields are fille­d. Once the user clicks on the­ "Check" button, the app examine­s whether the inputs form anagrams. In case­ they do, a success message­ with a green background is displayed. Howe­ver, if the inputs are not anagrams or if the­ input fields are empty, an message with a red background appe­ars. 

Steps to Create a React Application:

  • Create a react application by using this command
npx create-react-app anagramApp
  • After creating your project folder, i.e. anagramApp, use the following command to navigate to it:
cd anagramApp

Project Structure:

The package.json file will look like:

{
"name": "anagram-checker-app",
"version": "0.0.0",
"description": "Anagram Checker App using React",
"main": "index.js",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"dependencies": {
"react": "18.2.0",
"react-dom": "18.2.0",
"react-scripts": "4.0.3"
},
"devDependencies": {},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

Example : Write the below code in App.js file and style.css in the src directory

JavaScript
import React, { useState } from 'react'; import './style.css'; // Import the external CSS file  function App() {     const [word1, setWord1] = useState('');     const [word2, setWord2] = useState('');     const [result, setResult] = useState('');     const [isAnagram, setIsAnagram] = useState(false);     const [checkNumbers, setCheckNumbers] = useState(false);      const handleWord1Change = (e) => {         setWord1(e.target.value.toLowerCase());     };      const handleWord2Change = (e) => {         setWord2(e.target.value.toLowerCase());     };      const handleToggleChange = () => {         setCheckNumbers(!checkNumbers);     };      const checkAnagram = () => {              // Remove spaces and punctuation from both words         const cleanedWord1 = checkNumbers             ? word1.replace(/[^0-9]/g, '')             : word1.replace(/[^\w]/g, '');          const cleanedWord2 = checkNumbers             ? word2.replace(/[^0-9]/g, '')             : word2.replace(/[^\w]/g, '');          // Check if the lengths are the same         if (cleanedWord1.length !== cleanedWord2.length) {             setResult('Not an anagram');             setIsAnagram(false);             return;         }          // Count character occurrences in the first word         const charCount1 = {};         for (const char of cleanedWord1) {             charCount1[char] = (charCount1[char] || 0) + 1;         }          // Count character occurrences in the second word         const charCount2 = {};         for (const char of cleanedWord2) {             charCount2[char] = (charCount2[char] || 0) + 1;         }          // Compare character counts         for (const char in charCount1) {             if (charCount1[char] !== charCount2[char]) {                 setResult('Not an anagram');                 setIsAnagram(false);                 return;             }         }          // If all character counts are the same, it's an anagram         setResult("It's an anagram!");         setIsAnagram(true);     };      return (         <div className="container">             <h1 className="heading">Anagram Checker</h1>             <p className="desc">                 Enter two                  {checkNumbers ? 'numbers' : 'words'}                  to check if they are                 anagrams:             </p>             <div className="inputs">                 <input                     type="text"                     placeholder=                         {`Enter ${checkNumbers ? 'number' : 'word'} 1`}                     value={word1}                     onChange={handleWord1Change}                     className="input"                 />                 <input                     type="text"                     placeholder=                         {`Enter ${checkNumbers ? 'number' : 'word'} 2`}                     value={word2}                     onChange={handleWord2Change}                     className="input"                 />             </div>             <label className="toggleLabel">                 Check for numbers:                 <input                     type="checkbox"                     checked={checkNumbers}                     onChange={handleToggleChange}                     className="toggleCheckbox"                 />             </label>             <button id="btn" onClick={checkAnagram}                      className="button">                 Check             </button>             <p id="result"                 className={isAnagram ? 'result success' : 'result error'}>                 {result}             </p>         </div>     ); } export default App; 
CSS
/* style.css */ .container {     width: 90%;     max-width: 31.25em;     background-color: #ffffff;     padding: 2em;     position: absolute;     transform: translate(-50%, -50%);     left: 50%;     top: 50%;     border-radius: 1em;     font-family: 'Poppins', sans-serif;     box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); }  .heading {     font-size: 1.5em;     margin-bottom: 1em;     color: #0083e8;     text-align: center; }  .desc {     font-size: 1.2em;     margin: 1em 0 2em 0;     color: #333; }  .inputs {     display: grid;     grid-template-columns: 1fr 1fr;     gap: 2em; }  .input {     width: 100%;     border: 1px solid #ccc;     padding: 0.5em;     outline: none;     border-radius: 0.3em;     font-size: 1em; }  .button {     display: block;     margin: 0 auto;     background-color: #0083e8;     color: #ffffff;     border: none;     outline: none;     padding: 0.7em 2em;     border-radius: 0.5em;     font-size: 1em;     cursor: pointer; }  .toggleLabel {     display: flex;     align-items: center;     margin-bottom: 1em;     font-size: 1.2em;     color: #333; }  .toggleCheckbox {     margin: 10px; }  .result {     text-align: center;     margin-top: 1em;     font-size: 1.2em;     font-weight: bold; }  .success {     color: #078307;     background-color: #d0ffd0; }  .error {     color: #a00606;     background-color: #ffc4b0; } 

Steps to run the Application:

  • Type the following command in the terminal:
npm start
  • Type the following URL in the browser:
 http://localhost:3000/

Output:Build-a-Anagram-Checker-App-Using-React


Next Article
Build a Anagram Checker App Using ReactJS

S

saurabhkumarsharma05
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • Geeks Premier League
  • Geeks Premier League 2023

Similar Reads

    Create an Anagram Checker App using HTML CSS and JavaScript
    In this article, we will see how to create a web application that can verify if two input words are Anagrams or not, along with understanding the basic implementation through the illustration. An Anagram refers to a word or phrase that's created by rearranging the letters of another word or phrase u
    3 min read
    Build a Captcha Generator Using ReactJs
    A CAPTCHA generator is a tool that creates random and visually distorted text, requiring user input to prove they are human. It prevents automated bots from accessing websites or services by testing human comprehension. Our Captcha generator ge­nerates random text-base­d captchas that users must acc
    4 min read
    Emoji Picker App using React
    In this article, we will create an Interactive Emoji Application using ReactJS Framework. This developed project basically implements functional components and manages the state accordingly.The developed Application allows users to explore a wide range of emojis and select them for their communicati
    4 min read
    Create a Quiz App using ReactJS
    In this article, we will create a quiz application to learn the basics of ReactJS. We will be using class components to create the application with custom and bootstrap styling. The application will start with questions at first and then the score will be displayed at last. Initially, there are only
    4 min read
    Build a Dictionary App Using React Native
    In this article, we will implement a Dictionary app using React Native. The app allows users to effortlessly search for word meanings, access definitions, listen to pronunciations, and examine example sentences. To give you a better idea of what we’re going to create, let’s watch a demo video.Demo V
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences