previous

page 1

next
Introduction:

We're going to create the Words 4 Game in this tute. Creating the game is fairly straightforward but I found generating suitable sets of 4 words challenging. It will also be interesting for you to use JavaScript just as a programming language.

Preparation:

Type these 2 lines into Atom and save it as words4.html in a new folder, project_3:

<script src='words4.js'></script>
<script src='Sort.js'></script>

Why not index.html?
Because index.html will be used to make the game itself later.

Download this file and unzip it into your new directory.

words4.js contains a JavaScript array of 1827 four letter words.

Note that you're going to need Sort.js from Project 2.

diff_letters function

The first thing I did was to go through the list of 1827 words and make a new array that only contains words with all letters different. for this I wrote a function called diff_letters which returns true or false depending on whether the supplied word has all different letters or not.

One way to do this is to turn the word into an array of letters, sort this array and step through it checking each pair.

To do this you'll need a new function, split. Here's the start of my diff_letters function - see if you can finish it yourself. Note the empty string.

function diff_letters(word) {
var arr = word.split('');
previous
next