/ Learning to code

Here's How To Code Wordle — That Game That Everyone's Talking About

How to code Wordle online word game

If your social feeds are full of people sharing green, gray, and yellow square emojis, you’re probably familiar with Wordle, the deceptively simple online word game that’s blown up in recent months.

Wordle challenges you to guess a random five-letter word in six attempts. Playing Wordle can be frustratingly hard, but coding it was easy, according to Josh Wardle, who built the game in November as a fun activity for his wife. Now, hundreds of thousands of people play Wordle each day and share their stats (in the form of emoji squares) on social media.

Curious how a viral game like this gets made? Here are the skills you need to learn to code a game as simple and satisfying as Wordle:

How Wordle works

Wordle features a keyboard and 30 letter tiles that change color after each guess: A green square means you chose the right letter in the correct position, yellow means the word contains the letter in a different place, and gray means it’s not in the word at all. That’s it.

Wordle is intentionally understated, according to Wardle. “I built it as simply as possible,” Wardle, a Brooklyn-based software engineer who previously worked at Reddit, told TechCrunch.

It’s not an app or a piece of software, “it’s literally just a website and some JavaScript that downloads,” Wardle told TechCrunch. “And once it’s downloaded, it never needs to do anything again.” Wordle lives on Wardle’s personal website, which has no backend, so it doesn’t get bogged down by the growing fanbase, he told TechCrunch.

How to build a game like Wordle

All it takes to code a game like Wordle is JavaScript, HTML, and some CSS, explains Nik Dolan-Stern, a Curriculum Developer at Codecademy. “Essentially any beginner course on a language could teach you most of the mechanics of this game,” they say.

Once you have a handle on the programming language, Nik says ​​you could use for loops to create the mechanism that checks whether guess letters are in the solution. “All of that logic is fairly straightforward,” they say. “Okay, is this letter contained in this set of other letters? Is it both in the set and in the right position?”

For example, here's a code snippet that Nik wrote (check out their workspace here):

  for (let i = 0; i < guess.length; i++) {
    let guessLetter = guess.charAt(i);
    let solutionLetter = solution.charAt(i);
    if (guessLetter === solutionLetter) {
      result.push("Green");
    }
    else if (solution.indexOf(guessLetter) != -1) {
      result.push("Yellow");
    }
    else {
      result.push("Grey");
    }
  }

Wordle’s runaway success is proof that even beginner code can create cultural impact. “The fact that this is popular is so cool, because I love the idea of students seeing this and feeling like, ‘This is something I can make,’” Nik says.

For now, Wardle said that making a Wordle app is off the table. “I don’t have the skills,” he told TechCrunch. “I’d have to invest the time to learn how to do it, which I could do, but it would be an investment of my time.”

Motivated to build your own Wordle-like game? Start by taking our Learn JavaScript course, and then learn to build a video game app with our Game Development courses. You can share your progress (and get some help from the community, if you need) in our forums. And don't forget to post again to show off the finished product. Who knows? Maybe your game will go viral, too.


JavaScript Tutorial: Learn JavaScript For Free | Codecademy
Learn the JavaScript fundamentals you’ll need for front-end or back-end development.

Get more practice, more projects, and more guidance.

Here's How To Code Wordle — That Game That Everyone's Talking About
Share this