<div class="game__wrapper">
  <div id="start" class="game__start">
    <div>PATT<br />ERNS</div>
  </div>
  <div class="game__logo">
    PATT<br />
    ERNS
  </div>
  <div class="game__title-wrapper">
    <div id="title" class="game__title"></div>
  </div>
  <div id="game" class="game"></div>
  <div id="score" class="game__score">0</div>
</div>
@import url("https://fonts.googleapis.com/css2?family=Major+Mono+Display&display=swap");

$purple: #799df1;
$light-blue: #60c1ec;
$green: #7bd9de;
$pink: #cfb0d2;

$text: white;
$background: linear-gradient(
  60deg,
  $purple,
  $light-blue 30%,
  $green 60%,
  $pink 90%
);
$black: #000038;

html {
  @media (max-width: 767px) {
    font-size: 12px;
  }
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  color: $text;
  background: $background;
  background-size: 100% 100%;
  overflow: hidden;
  font-family: "Major Mono Display", monospace;
}

.game {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  color: $black;
  &__wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  &__start {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    font-size: 35vh;
    background: $background;
    transition: transform 1s ease;
    cursor: pointer;
    &:after {
      content: "";
      position: absolute;
      top: calc(50% - 10vh);
      left: calc(50% - 6.5vh);
      border-top: 13vh solid transparent;
      border-bottom: 13vh solid transparent;
      border-left: 20vh solid $black;
      pointer-events: none;
      transition: transform 1s ease;
    }
    &:hover {
      transform: scale(1.1);
      &:after {
        transform: scale(1.2);
      }
    }
    @media (max-width: 767px) {
      font-size: 30vw;
      &:after {
        top: calc(50% - 10vw);
        left: calc(50% - 6.5vw);
        border-top: 13vw solid transparent;
        border-bottom: 13vw solid transparent;
        border-left: 20vw solid $black;
      }
    }
  }
  &__logo {
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-size: 1.5rem;
    color: $text;
  }
  &__title-wrapper {
    display: flex;
    justify-content: center;
    font-size: 3rem;
  }
  &__title {
    color: $text;
    text-transform: uppercase;
    text-align: center;
    padding: 1rem;
  }
  &__pattern {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    text-align: right;
    width: 12rem;
    padding: 1rem;
  }
  &__pattern-text {
    width: 100%;
    margin-top: 1rem;
    line-height: 1.2;
    word-wrap: break-word;
  }
  &__score {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    font-size: 2rem;
    color: $text;
  }
}

.tile {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 5rem;
  height: 5rem;
  margin: 0.5rem;
  font-size: 4rem;
  border-radius: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  &:hover {
    transform: scale(1.2) rotate(-10deg);
    z-index: 1;
    box-shadow: -0.2rem 0.5rem 0.5rem 0 rgba($black, 0.5);
  }
}
View Compiled
const game = document.getElementById("game");
const start = document.getElementById("start");
const title = document.getElementById("title");
const scoreElement = document.getElementById("score");

let score = 0;

let level = 0;
let stage = 0;

const prepareTile = (id) => {
  const tile = document.createElement("div");
  tile.classList.add("tile");
  tile.id = id;
  return tile;
};

const basicBuildFunction = (id) => {
  const tile = prepareTile(id);
  tile.innerHTML = id;
  return tile;
};

function shuffle(array) {
  let currentIndex = array.length;

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

    // And swap it with the current element.
    [array[currentIndex], array[randomIndex]] = [
      array[randomIndex],
      array[currentIndex]
    ];
  }
}

const firstLevel = [
  {
    title: "Bigger",
    stages: [
      {
        tiles: ["10", "20", "30", "40"],
        correct: "40"
      },
      {
        tiles: ["35", "33", "36", "40"],
        correct: "40"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      const px = document.createElement("div");
      px.style = `background-color: #000038; width: ${id}px; height: ${id}px; pointer-events: none`;
      tile.appendChild(px);
      return tile;
    }
  }
];

const levelList = [
  {
    title: "Pure",
    stages: [
      {
        tiles: ["#ff12e0", "#a2fafb", "#ffbb00", "#ff0000"],
        correct: "#ff0000"
      },
      {
        tiles: [
          "#2bbee1",
          "#09ffbb",
          "#aaff00",
          "#213611",
          "#bb0099",
          "#0000ff",
          "#21ff00",
          "#f99abb"
        ],
        correct: "#0000ff"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.style.backgroundColor = id;
      return tile;
    }
  },
  {
    title: "Happier",
    stages: [
      {
        tiles: ["๐Ÿ˜ฌ", "๐Ÿ˜•", "๐Ÿ˜•", "๐Ÿ™ƒ"],
        correct: "๐Ÿ™ƒ"
      },
      {
        tiles: ["๐Ÿ˜š", "๐Ÿ™‚", "๐Ÿ˜€", "๐Ÿ™ƒ", "๐Ÿ˜ต", "๐Ÿ˜ตโ€๐Ÿ’ซ", "๐Ÿ˜‘", "๐Ÿ˜˜"],
        correct: "๐Ÿ˜€"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Symetrical",
    stages: [
      {
        tiles: ["๐Ÿซข", "๐Ÿ˜ช", "๐Ÿซฅ", "๐Ÿ˜ฐ"],
        correct: "๐Ÿซฅ"
      },
      {
        tiles: ["๐Ÿ‘ป", "๐Ÿ˜ถโ€๐ŸŒซ๏ธ", "๐ŸŠ", "๐Ÿผ", "๐Ÿก", "๐Ÿ˜œ"],
        correct: "๐Ÿผ"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Empty",
    stages: [
      {
        tiles: ["1", "2", "0", "3"],
        correct: "0"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      const px = document.createElement("div");
      px.style = `background-color: #000038; width: ${id}px; height: ${id}px; pointer-events: none`;
      tile.appendChild(px);
      return tile;
    }
  },
  {
    title: "Leftie",
    stages: [
      {
        tiles: ["๐Ÿซฒ", "๐Ÿค™", "๐Ÿ‘Œ", "๐Ÿ‘"],
        correct: "๐Ÿ‘"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Prime",
    stages: [
      {
        tiles: ["9", "4", "1", "8"],
        correct: "1"
      },
      {
        tiles: ["12", "7", "9", "4"],
        correct: "7"
      },
      {
        tiles: ["77", "61", "91", "4"],
        correct: "61"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.innerHTML = id;
      tile.style.fontSize = "2rem";
      return tile;
    }
  },
  {
    title: "Fast",
    stages: [
      {
        tiles: ["๐Ÿฅ", "๐Ÿฅ“", "๐ŸŒญ", "๐Ÿฅฉ"],
        correct: "๐ŸŒญ"
      },
      {
        tiles: ["๐Ÿซ˜", "๐ŸŒฏ", "๐Ÿง„", "๐Ÿž", "๐Ÿง€", "๐Ÿท"],
        correct: "๐ŸŒฏ"
      },
      {
        tiles: ["๐Ÿ", "๐Ÿ…", "๐Ÿฅ ", "๐Ÿ•", "๐Ÿช", "๐Ÿจ", "๐Ÿฌ"],
        correct: "๐Ÿ•"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Turquoise",
    stages: [
      {
        tiles: ["#00ccff", "#00ffff", "#00ffcc", "#00fddf"],
        correct: "#00ffff"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.style.backgroundColor = id;
      return tile;
    }
  },
  {
    title: "Europe",
    stages: [
      {
        tiles: ["๐Ÿ‡ป๐Ÿ‡บ", "๐Ÿ‡ง๐Ÿ‡ช", "๐Ÿ‡ฆ๐Ÿ‡บ", "๐Ÿ‡ฏ๐Ÿ‡ต"],
        correct: "๐Ÿ‡ง๐Ÿ‡ช"
      },
      {
        tiles: ["๐Ÿ‡ฎ๐Ÿ‡ช", "๐Ÿ‡ต๐Ÿ‡ญ", "๐Ÿ‡บ๐Ÿ‡พ", "๐Ÿ‡ง๐Ÿ‡ด"],
        correct: "๐Ÿ‡ฎ๐Ÿ‡ช"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "45deg",
    stages: [
      {
        tiles: ["45", "40", "25", "30"],
        correct: "45"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      const px = document.createElement("div");
      px.style = `background-color: #000038; width: 50%; height: 50%; transform: rotate(${id}deg); pointer-events: none`;
      tile.appendChild(px);
      return tile;
    }
  },
  {
    title: "Top",
    stages: [
      {
        tiles: ["0", "-10", "-5", "-18"],
        correct: "-18"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      const px = document.createElement("div");
      px.style = `background-color: #000038; width: 50%; height: 50%; transform: translateY(${id}px); pointer-events: none`;
      tile.appendChild(px);
      return tile;
    }
  },
  {
    title: "???",
    stages: [
      {
        tiles: ["๐Ÿฆ", "๐Ÿป", "๐Ÿฆ…", "๐Ÿฆ“"],
        correct: "๐Ÿฆ“"
      },
      {
        tiles: ["๐ŸŠ", "๐ŸฆŒ", "๐ŸฆŠ", "๐Ÿถ"],
        correct: "๐ŸฆŒ"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Bigger than",
    stages: [
      {
        tiles: [">", "<", "=", "ร—", "รท"],
        correct: ">"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Later",
    stages: [
      {
        tiles: ["๐Ÿ•’", "๐Ÿ•—", "๐Ÿ• ", "๐Ÿ•š"],
        correct: "๐Ÿ•š"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "???",
    stages: [
      {
        tiles: ["๐Ÿ†", "๐ŸŒฝ", "๐Ÿฅ•", "๐Ÿ‹"],
        correct: "๐Ÿ‹"
      },
      {
        tiles: ["๐Ÿฅ”", "๐Ÿง…", "๐Ÿซ‘", "๐Ÿ“"],
        correct: "๐Ÿ“"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.innerHTML = id;
      return tile;
    }
  },
  {
    title: "???",
    stages: [
      {
        tiles: ["๐Ÿ€", "๐ŸฅŽ", "๐ŸŽฑ", "๐Ÿ"],
        correct: "๐ŸŽฑ"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "School?",
    stages: [
      {
        tiles: ["๐Ÿ–‹๏ธ", "๐Ÿ“", "๐Ÿ–๏ธ", "๐ŸŽ’", "๐Ÿ”ง"],
        correct: "๐Ÿ”ง"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "???",
    stages: [
      {
        tiles: ["๐Ÿˆ", "โšฝ", "โšพ", "๐ŸฅŽ"],
        correct: "๐Ÿˆ"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Warmer",
    stages: [
      {
        tiles: ["#ff0000", "#ff3344", "#ff00ee", "#ff2222", "#ff9900"],
        correct: "#ff0000"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.style.backgroundColor = id;
      return tile;
    }
  },
  {
    title: "Lighter",
    stages: [
      {
        tiles: ["#eeeedd", "#ccbbbb", "#bbcccc", "#ddccdd", "#aa99aa"],
        correct: "#eeeedd"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.style.backgroundColor = id;
      return tile;
    }
  },
  {
    title: "Black",
    stages: [
      {
        tiles: ["#000000", "#000022", "#330000", "#111111", "#222200"],
        correct: "#000000"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.style.backgroundColor = id;
      return tile;
    }
  },
  {
    title: "Light?",
    stages: [
      {
        tiles: ["๐Ÿ•ฏ๏ธ", "๐Ÿ’ก", "๐Ÿ”ฆ", "๐Ÿงจ"],
        correct: "๐Ÿงจ"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "???",
    stages: [
      {
        tiles: ["๐Ÿถ", "๐Ÿฑ", "๐Ÿน", "๐ŸฆŠ"],
        correct: "๐ŸฆŠ"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Love?",
    stages: [
      {
        tiles: ["๐Ÿ’œ", "๐Ÿ’™", "๐Ÿ’š", "๐Ÿ’›", "๐Ÿฉท", "๐Ÿ’”"],
        correct: "๐Ÿ’”"
      }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Moon?",
    stages: [
      { tiles: ["๐ŸŒ’", "๐ŸŒ“", "๐ŸŒ”", "๐ŸŸก", "๐ŸŒ–", "๐ŸŒ—", "๐ŸŒ˜", "๐ŸŒ‘"], correct: "๐ŸŸก" }
    ],
    buildFunction: basicBuildFunction
  },
  {
    title: "Ace?",
    stages: [{ tiles: ["โ™ ๏ธŽ", "โ™ฅ๏ธŽ", "โ™ฆ๏ธŽ", "โ™ฃ๏ธŽ", "โ™Ÿ๏ธŽ"], correct: "โ™Ÿ๏ธŽ" }],
    buildFunction: basicBuildFunction
  },
  {
    title: "Death?",
    stages: [{ tiles: ["๐Ÿชฆ", "๐Ÿ‘ป", "๐Ÿ’€", "โ›„"], correct: "โ›„" }],
    buildFunction: basicBuildFunction
  },
  {
    title: "America?",
    stages: [{ tiles: ["๐Ÿ‡ฒ๐Ÿ‡ฝ", "๐Ÿ‡จ๐Ÿ‡บ", "๐Ÿ‡ง๐Ÿ‡ท", "๐Ÿ‡จ๐Ÿ‡ด", "๐Ÿ‡ฎ๐Ÿ‡น"], correct: "๐Ÿ‡ฎ๐Ÿ‡น" }],
    buildFunction: basicBuildFunction
  },
  {
    title: "???",
    stages: [{ tiles: ["๐Ÿฅณ", "๐ŸŽŠ", "๐ŸŽˆ", "๐ŸŽ‰"], correct: "๐ŸŽˆ" }],
    buildFunction: basicBuildFunction
  },
  {
    title: "Transparent",
    stages: [
      {
        tiles: ["#799df1", "transparent", "#60c1ec", "#7bd9de", "#cfb0d2"],
        correct: "transparent"
      }
    ],
    buildFunction: (id) => {
      const tile = prepareTile(id);
      tile.style.backgroundColor = id;
      return tile;
    }
  },
  {
    title: "???",
    stages: [{ tiles: ["๐ŸŽธ", "๐Ÿ’ป", "๐Ÿ“ฑ", "๐Ÿช‡"], correct: "๐Ÿช‡" }],
    buildFunction: basicBuildFunction
  }
];

shuffle(levelList);

const levels = [...firstLevel, ...levelList];

const checkTile = (event) => {
  if (event.target.id === levels[level].stages[stage].correct) {
    score = score + 2;
    winStage();
  } else {
    score = score - 1;
    event.target.style.opacity = "30%";
  }
  scoreElement.innerHTML = score;
};

const generateLevel = () => {
  game.innerHTML = "";
  const currentLevel = levels[level];
  title.innerHTML = `${level}-${currentLevel.title}`;

  const tiles = currentLevel.stages[stage].tiles;
  shuffle(tiles);

  tiles.forEach((tile) => {
    const tileElement = currentLevel.buildFunction(tile);
    tileElement.addEventListener("click", checkTile);
    game.appendChild(tileElement);
  });
};

const winGame = () => {
  score.innerHTML = "";
  game.style.fontSize = "2rem";
  game.innerHTML = `Your score is ${score} ${
    score > 10 ? (score > 40 ? "๐Ÿ˜„" : "๐Ÿคจ") : "๐Ÿ˜จ"
  }`;
  title.innerHTML = "THE END";
};

const winStage = () => {
  stage++;
  if (stage >= levels[level].stages.length) {
    level++;
    stage = 0;

    if (level >= levels.length) {
      winGame();
      return;
    }
  }
  generateLevel();
};

start.addEventListener("click", () => (start.style.display = "none"));

generateLevel();

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.