previous

page 14

next
Adding the letters

We'll need the ids for each word in more than one function so I'm going to store them in a global variable too.
And I plan to call the function that loads the words, load_words().
So here is the bottom of my index.html but don't forget the top too!

</div>
<script>
var g_word_ids=
[[0,1,2,3],[0,4,8,12],[3,7,11,15],[12,13,14,15]];
var g_set=word4_sets[0];
load_words();
</script>
</body>
</html>

Have a go at writing load_words() yourself.

function load_words() {
for (var i=0;i<4;i++) {
var letters=g_set[i].split('');
var arr=g_word_ids[i];
for (var j=0;j<4;j++) {
var id=arr[j];
var element=document.getElementById(id);
element.textContent=letters[j];
}
}
}
previous
next