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
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