previous

page 19

next
Final words_check()

We need tell the player when correct words are in the wrong place.
The else at the end will achieve this.
Also study the second line at the top and the two new lines at the bottom.
We have to use innerHTML instead of textContent otherwise the <br> will not be recognised by the browser.

function words_check() {
var s='';
for (var i=0;i<4;i++) {
var word='';
var arr=g_word_ids[i];
for (var j=0;j<4;j++) {
var id=arr[j];
var element=document.getElementById(id);
word=word+element.textContent;
}
if (word==g_set[i]) {
for (var j=0;j<4;j++) {
var id=arr[j];
var element=document.getElementById(id);
element.style.borderColor='green';
element.style.color='brown';
}
} else {
for (var j=0;j<4;j++) {
if (word==g_set[j]) {
s=s+word+' is in the wrong place<br>';
}
}
}
}
var element=document.getElementById('message');
element.innerHTML=s;
}
previous
next