What is JavaScript used for? Explaining with Wordle

What is javascript used for? Explaining with Wordle

You've been told you need to learn JavaScript. Great! But what is JavaScript actually used for? Let's explain with Wordle, the popular word game.

Wordle is made entirely by client-side JavaScript in the user's browser (as opposed to using server-side code). Although John Wardle sold Wordle for $1m+ to the New York Times, it's actually a reasonably simple game to make involving only HTML, CSS and JavaScript. You don't have to use any databases, APIs or any back end code.

HTML is used for showing text and symbols of the navigation bar at the top of the screen, the grid of boxes for making your guesses and the letters below.

CSS powers the animation and the change of color when you make a guess. As well as arranging the layout of the page so it fits the screen regardless of what type of device you use.

JavaScript handles everything else - let's get into more detail.

Interacting with a website

In Wordle JavaScript is used as a programming tool for taking input from a user and checking for certain things.

Wordle needs to perform several tasks:

  • enter the letters you pressed into the empty boxes
  • check if the word you entered is correct (good luck on the first turn!)
  • return the letters you got right and give it a color of orange
  • return the letter you got wrong and give it a color of grey
  • return the letter you got right which is also in the right position and give it a color of green
  • mark the letters you've already tried in the keyboard below
  • check if your guess is a valid word

coding mentors

Sending a message to the user

When you guess correctly or run out of guesses, Wordle flashes a message such as "splendid" , depending on how many guesses you took.

JavaScript is working here.

The developer has written JavaScript to say something in English like this:

"if the user takes 4 guesses, show 'splendid' "

Local storage

Wordle uses local storage in your browser so it can set the secret word, can remember how many games you've played, show what your scores are etc.

JavaScript is also used to show a countdown timer until you can next play Wordle.

How to learn JavaScript without a degree

Ok, now you've learned what JavaScript is used for you should learn it! Check out the popular Beginner JavaScript course by WesBos. If you know some JavaScript already, you can start with his React for Beginners course (affiliate) and get into the world of modern JavaScript.

Or get help with coding from our experienced JavaScript mentors

About the author
Pete Codes

Pete Codes

Hey, I'm Pete and the creator of this site. I am a self-taught web developer and I'm based in Edinburgh, Scotland.

Self-taught developer success stories

Get into tech without a CS degree

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Self-taught developer success stories.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.