Word Scramble Game using JavaScript Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report This article will demonstrate the creation of a Word Scramble Game using JavaScript. Word Scramble Game is a simple quiz game based on the rearrangement of letter to make a random word and the user have to guess the correct word out of it with the help of provided hint. If the user is able to guess the correct word it gives the result 'correct' and if he guesses wrong it shows 'incorrect'. On completion, this game will look like this: Prerequisites:HTMLCSSJavaScriptApproach:Create the basic game layout using the HTML tags like divs, headings for titles and scrambled word and input, and buttons for taking user input and verification along with the relevant class names and ids as shown in the code example,Then, use those classes and ids to apply to style using the CSS properties like display, align content for structure, padding, margin, font size, background-color, and border to give it a better appearance.In JavaScript create a sample list of words and hints. Use the Math.random() method to get a random index to display the word and the hint using the document. getElementById method.Before displaying shuffle the letters of the word using math.randon and swap using a custom shuffle function.Define a function refresh to refresh the scrambled word and hint when the refresh button is clicked. Use the check function to verify the user input by clicking on the check button and displaying the resulting output.Example: In this example, we will create a word sample game with a list of sample words and hints using the approach above mentioned.  HTML <!--index.html--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>word scramble</title> <link href="style.css" rel="stylesheet" /> </head> <body> <div class="root"> <h1 class="title">Word Scramble Game</h1> <div id="scrambled"> <h2 id="scrambleWord">Word</h2> <p id="hint"></p> </div> <div id="form"> <input id="input" type="text" placeholder="Guess correct word" /> </div> <h3 id="output">Result:</h3> <div class="foot"> <button type="button" onclick="check()"> Check </button> <button type="button" onclick="refresh()"> Refresh </button> </div> <script src="script.js"></script> </div> </body> </html> CSS /* style.css */ body { display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 50vh; } .root { font-size: x-large; color: whitesmoke; background-color: rgb(57, 151, 57); box-shadow: 0 2px 5px grey; padding: 0% 5% 1% 5%; text-align: center; border-radius: 5px 0; } .title { border-bottom: 4px dashed; border-color: white; } input { font-size: 20px; padding-left: 10px; outline: 2px grey; } .foot { margin-bottom: 0%; display: flex; width: 100%; } .foot>button { width: 48%; padding: 1%; margin: 1%; background-color: rgb(41, 117, 41); border-radius: 5px; border-color: rgb(29, 90, 29); font-size: large; } JavaScript // script.js const words = [ "react", "angular", "javascript", "bootstrap", "tailwind", ]; // Respective list of hints const hints = [ "JavaScript framework", "JavaScript Framework", "Scripting Language", "Styling Library", "Styling Library", ]; // Initialize display word let displayWord = ""; // Function to shuffle letters function shuffle(str) { strArray = Array.from(str); for (let i = 0; i < strArray.length - 1; ++i) { let j = Math.floor(Math.random() * strArray.length); // Swap letters let temp = strArray[i]; strArray[i] = strArray[j]; strArray[j] = temp; } return strArray.join(" "); } // Function to check input and display result function check() { let input = document.getElementById("input"); let output = document.getElementById("output"); if ( input.value.toLocaleLowerCase() === displayWord.toLocaleLowerCase() ) output.innerHTML = "Result: Correct"; else output.innerHTML = "Result: Incorrect"; } // To refresh and show new word function refresh() { index = Math.floor(Math.random() * 5); displayWord = words[index]; displayHint = hints[index]; scrambleWord = document.getElementById("scrambleWord"); scrambleWord.innerText = shuffle(displayWord).toUpperCase(); let hint = document.getElementById("hint"); hint.innerHTML = "<b>Hint:</b> " + displayHint; document.getElementById("output").innerText = "Result:"; } // Function call when page load for first time refresh(); Output: Comment More infoAdvertise with us J jatinsharmatu54 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Projects Similar Reads Create a snake game using HTML, CSS and JavaScript Snake Game is a single-player game where the snake gets bigger by eating the food and tries to save itself from the boundary of the rectangle and if the snake eats their own body the game will be over.Game Rules:If the snake goes out of the boundary or eats its own body the game will be over.Prerequ 4 min read Design Dragon's World Game using HTML CSS and JavaScript Project Introduction: "Dragon's World" is a game in which one dragon tries to save itself from the other dragon by jumping over the dragon which comes in its way. The score is updated when one dragon saves himself from the other dragon. The project will contain HTML, CSS and JavaScript files. The H 6 min read Word Guessing Game using HTML CSS and JavaScript In this article, we will see how can we implement a word-guessing game with the help of HTML, CSS, and JavaScript. Here, we have provided a hint key & corresponding total number of gaps/spaces depending upon the length of the word and accept only a single letter as an input for each time. If it 4 min read Build a Memory Card Game Using HTML CSS and JavaScript A memory game is a type of game that can be used to test or check the memory of a human being. It is a very famous game. In this game, the player has some cards in front of him and all of them facing down initially. The player has to choose a pair of cards at one time and check whether the faces of 6 min read Create a Simon Game using HTML CSS & JavaScript In this article, we will see how to create a Simon Game using HTML, CSS, and JavaScript. In a Simon game, if the player succeeds, the series becomes progressively longer and more complex. Once the user is unable to repeat the designated order of the series at any point, the game is over.Prerequisite 5 min read Create a Minesweeper Game using HTML CSS & JavaScript Minesweeper is a classic puzzle game that challenges your logical thinking and deduction skills. It's a great project for developers looking to improve their front-end web development skills. In this article, we'll walk through the steps to create a Minesweeper game using HTML, CSS, and JavaScript. 4 min read Whack-a-Mole Game using HTML CSS and JavaScript Whack-A-Mole is a classic arcade-style game that combines speed and precision. The game is set in a grid of holes, and the objective is to "whack" or hit the moles that randomly pop up from these holes. In this article, we are going to create Whack-a-Mole using HTML, CSS and JavaScript.Preview Image 3 min read Simple HTML CSS and JavaScript Game Tap-the-Geek is a simple game, in which the player has to tap the moving GeeksForGeeks logo as many times as possible to increase their score. It has three levels easy, medium, and hard. The speed of the circle will be increased from level easy to hard. I bet, it is very difficult for the players to 4 min read Design Hit the Mouse Game using HTML, CSS and Vanilla Javascript In this article, we are going to create a game in which a mouse comes out from the holes, and we hit the mouse with a hammer to gain points. It is designed using HTML, CSS & Vanilla JavaScript.HTML Code:First, we create an HTML file (index.html).Now, after creating the HTML file, we are going to 5 min read Create a 2D Brick Breaker Game using HTML CSS and JavaScript In this article, we will see how to create a 2D Brick Breaker Game using HTML CSS & JavaScript. Most of you already played this game on your Mobile Phones where you control a paddle to bounce a ball, aiming to demolish a wall of bricks arranged at the top of the screen. 2D Brick Breaker Game is 8 min read Like