Build a Word Scramble Solver Strategy Game in HTML5 CSS3 and Javascript Full Project For Beginners

Build a Word Scramble Solver Strategy Game in HTML5 CSS3 and Javascript Full Project For Beginners


Welcome folks today in this blog post we will be building a word scramble solver strategy game in html5 css3 and javascript. All the full source code of the application is shown below.



Get Started



In order to get started you need to make an index.html file and copy paste the following code




<html lang="en" dir="ltr">
    <h1>Scrambled Words</h1>
    <div id="contact">
      <a target="_blank" href=""><i class="fab fa-github"></i></a>
      <a target="_blank" href=""><i class="fab fa-codepen"></i></a>
      <a target="_blank" href=""><i class="fab fa-twitter"></i></a>
    <div id="rules">
      <p class="lead">Unscamble the words.</p>
      <p>Type in your guess <small>(Enter works)</small>.</p>
      <p>Get three correct and level up.</p>
      <p>Get a word wrong three times and restart.</p>
      <p>Finish level 8 and you win.</p>
      <p>Good luck!</p>
      <button id="play-btn">Let's Play</button>

  <div id="game-container" class="hidden">
    <p>Level: <span id="level">1</span></p>
    <p>Score: <span id="score">0</span></p>
    <p>Attempts: <span id="attempts">0</span></p>
    <p id="info"></p>

    <div id="guess-container">
      <p id="scrambled-word"></p>

      <input id="user-guess" type="text" placeholder="Enter your guess">
      <button id="submit">Submit</button>
      <button id="reset-btn">Reset</button>


  <div id="copyright">
    <p>Coded by: <a target="_blank" href="">Alex Johnson</a></p>




Now make a style.css file and copy paste the below code




/* v2.0 | 20110126 License: none (public domain) */
/* line 6, ../sass/partials/_normalize.scss */
 html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
     margin: 0;
     padding: 0;
     border: 0;
     font-size: 100%;
     font: inherit;
     vertical-align: baseline;
/* HTML5 display-role reset for older browsers */
/* line 27, ../sass/partials/_normalize.scss */
 article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
     display: block;
/* line 31, ../sass/partials/_normalize.scss */
 body {
     line-height: 1;
/* line 34, ../sass/partials/_normalize.scss */
 ol, ul {
     list-style: none;
/* line 37, ../sass/partials/_normalize.scss */
 blockquote, q {
     quotes: none;
/* line 40, ../sass/partials/_normalize.scss */
 blockquote:before, blockquote:after, q:before, q:after {
     content: "";
     content: none;
/* line 45, ../sass/partials/_normalize.scss */
 table {
     border-collapse: collapse;
     border-spacing: 0;
/* line 5, ../sass/styles.scss */
 html, body {
     font-size: 16px;
     width: 100%;
     font-family: "Quicksand", sans-serif;
     overflow-x: hidden;
     overflow-y: hidden;
/* line 13, ../sass/styles.scss */
 nav {
     border-bottom: #e18a07 2px solid;
     width: 100%;
     padding: 0.625em;
     display: block;
     height: 2em;
/* line 20, ../sass/styles.scss */
 h1 {
     font-size: 2em;
     display: inline-block;
     float: left;
     padding-left: 1em;
/* line 26, ../sass/styles.scss */
 #contact {
     font-size: 2em;
     display: inline-block;
     float: right;
     padding-right: 1em;
/* line 32, ../sass/styles.scss */
 #contact a {
     color: #000;
/* line 35, ../sass/styles.scss */
 #contact i:hover {
     color: #e18a07;
     cursor: pointer;
/* line 40, ../sass/styles.scss */
 #rules {
     position: absolute;
     z-index: 999;
     width: 31.25em;
     height: 31.25em;
     text-align: center;
     left: 50%;
     margin-left: -200px;
     top: 50%;
     margin-top: -200px;
/* line 51, ../sass/styles.scss */
 #rules p {
     margin-bottom: 1.25em;
/* line 55, ../sass/styles.scss */
 #game-container {
     text-align: center;
     margin: 2em auto;
     width: 100vh;
     height: 80vh;
/* line 62, ../sass/styles.scss */
 #game-container p {
     display: inline-block;
     margin-right: 1em;
     margin-bottom: 3em;
     font-weight: 500;
     font-size: 1.5em;
/* line 69, ../sass/styles.scss */
 #game-container p span {
     font-weight: 300;
/* line 72, ../sass/styles.scss */
 #game-container p#info {
     display: block;
     text-align: center;
     font-size: 2em !important;
     height: 2em;
     margin-bottom: 1em;
/* line 80, ../sass/styles.scss */
 #scrambled-word {
     font-size: 3em !important;
     font-family: "Anton", sans-serif;
     text-transform: uppercase;
     display: block;
     margin-left: 48px;
     margin-bottom: 1em !important;
/* line 89, ../sass/styles.scss */
 #scrambled-word p {
     display: block;
     width: 100%;
/* line 94, ../sass/styles.scss */
 #user-guess {
     display: block;
     width: 20em;
     height: 3em;
     padding-left: 1em;
     margin: 0 auto 1.25em;
     border: 1px solid #000;
     outline-color: #e18a07;
     font-size: 1.1em;
/* line 104, ../sass/styles.scss */
 small {
     font-size: 0.8em;
/* line 107, ../sass/styles.scss */
 .lead {
     font-size: 1.2em;
     font-weight: 700;
/* line 111, ../sass/styles.scss */
 .correct, .incorrect {
     font-size: 1.5em;
     font-weight: 700;
/* line 116, ../sass/styles.scss */
 .correct {
     color: green;
     display: block;
/* line 121, ../sass/styles.scss */
 .incorrect {
     color: red;
     display: block;
/* line 126, ../sass/styles.scss */
 .hidden {
     visibility: hidden;
/* line 129, ../sass/styles.scss */
 button {
     cursor: pointer;
     width: 12em;
     height: 3em;
     outline: none;
     text-transform: uppercase;
     font-weight: 400;
     font-size: 1.1em;
/* line 138, ../sass/styles.scss */
 #submit, #play-btn {
     background: #fff;
     border: 2px solid #e18a07;
/* line 143, ../sass/styles.scss */
 #submit:hover, #play-btn:hover {
     background: #e18a07;
     color: #fff;
     transition: 0.2s background;
/* line 150, ../sass/styles.scss */
 #reset-btn {
     background: #fff;
     border: none;
     box-shadow: 1px 1px 1px #999;
/* line 155, ../sass/styles.scss */
 #reset-btn:hover {
     box-shadow: 1px 1px 1px #000;
     transition: 0.2s box-shadow;
/* line 161, ../sass/styles.scss */
 button:active {
     position: relative;
     top: 1px;
/* line 166, ../sass/styles.scss */
 #copyright {
     text-align: center;


See also  Build Random Fun Facts or Quote Generator in Browser Using HTML5 CSS3 and Javascript Full Project For Beginners


Now make a script.js file and copy paste the following code




const userGuess = document.getElementById("user-guess");
const submitBtn = document.getElementById("submit");
const usersWord = document.getElementById("scrambled-word");
const info = document.getElementById("info");
const levelOutput = document.getElementById("level");
const scoreOutput = document.getElementById("score");
const attemptsOutput = document.getElementById("attempts");
const gameContainer = document.getElementById("game-container");
const guessContainer = document.getElementById("guess-container");
const rules = document.getElementById("rules");
const playBtn = document.getElementById("play-btn");
const resetBtn = document.getElementById("reset-btn");

let level = 1;
let score = 0;
let word;
let attempts = 0;
let correct = 0;

const lvlOneWords = [

const lvlTwoWords = [

const lvlThreeWords = [

const lvlFourWords = [

const lvlFiveWords = [

const lvlSixWords = [

const lvlSevenWords = [

const lvlEightWords = [

function reset() {
  level = 1;
  score = 0;
  correct = 0;
  attempts = 0;
  word = "";
  info.innerHTML = "";
  userGuess.value = "";

function randomWord(lvl) {
  word = lvl[Math.floor(Math.random() * lvl.length + 1) - 1];
  return word;

function scrambleWord(word) {
  let letters = word.split("");
  let currentIndex = letters.length,

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = letters[currentIndex];
    letters[currentIndex] = letters[randomIndex];
    letters[randomIndex] = temporaryValue;

  return letters.join(" ");
function updateBoard() {
  scoreOutput.innerHTML = score;
  levelOutput.innerHTML = level;
  attemptsOutput.innerHTML = attempts;

function checkAnswer(guess) {
  console.log(`Correct: ${correct}`);
  if (correct == 3) {
    level += 1;
    correct = 0;

  if (attempts == 3) {
    info.innerHTML =
      "<p class='retry'>Sorry. You are out of chances. <button id='retry-button'>Retry</button> </p>";

  if (guess === word) {
    info.innerHTML = "<span class='correct'>CORRECT</span>";
    score += 1;
    correct += 1;
    attempts = 0;
  } else {
    info.innerHTML = "<span class='incorrect'>Bzzzt! That's not right!</span>";
    score -= 1;
    attempts += 1;


function setLevel() {
  if (level == 1) {
  } else if (level == 2) {
  } else if (level == 3) {
  } else if (level == 4) {
  } else if (level == 5) {
  } else if (level == 6) {
  } else if (level == 7) {
  } else if (level == 8) {
  } else if (level == 9) {
    info.innerHTML =
      "<span class='win'>You Win! Great job! </br> You can reset or keep playing.</span>";

  console.log(`Word: ${word}`);
  usersWord.innerHTML = scrambleWord(word);

playBtn.addEventListener("click", function(e) {

submitBtn.addEventListener("click", function(e) {
  userGuess.value = "";

  function(e) {
    if (e.keyCode == 13) {
      userGuess.value = "";

resetBtn.addEventListener("click", function(e) {
  userGuess.value = "";



See also  Javascript Project to Show HTML5 Context Menu on Mouse Right Click on Element in Browser Full Project For Beginners


Now if you open the index.html file inside the browser you will see the below output


Leave a Reply