
previous

page 5
next
make_word4_sets.html
<script src='my_words4.js'></script>
<script src='word2.js'></script>
<script>
// try each word as the top word
for (var i=0; i<my_words4.length; i++) {
var w1=my_words4[i];
var w2=word2(w1);
}
</script>
<script src='word2.js'></script>
<script>
// try each word as the top word
for (var i=0; i<my_words4.length; i++) {
var w1=my_words4[i];
var w2=word2(w1);
}
</script>
You probably didn't go this far but hopefully you can see where I'm going.
The word2 function will return a suitable word if it can find one, '' if it can't.
You'll again need the split function if you are going to try by yourself.
You'll also need to know that != is JavaScript for not equal to.
word2.js
function word2(w1) {
var a1=w1.split('');
// try each word till we find one that fits
for (var i=0; i<my_words4.length; i++) {
var w2=my_words4[i];
var a2=w2.split('');
// first letters must be the same
if (a1[0]==a2[0]) {
// second letters must be different
if (a1[1]!=a2[1]) {
// third letters must be different
if (a1[2]!=a2[2]) {
// corner letters must be different
if (a1[3]!=a2[3]) {
return w2; // success
}
}
}
}
}
return ''; // tried all words - no luck
}
var a1=w1.split('');
// try each word till we find one that fits
for (var i=0; i<my_words4.length; i++) {
var w2=my_words4[i];
var a2=w2.split('');
// first letters must be the same
if (a1[0]==a2[0]) {
// second letters must be different
if (a1[1]!=a2[1]) {
// third letters must be different
if (a1[2]!=a2[2]) {
// corner letters must be different
if (a1[3]!=a2[3]) {
return w2; // success
}
}
}
}
}
return ''; // tried all words - no luck
}
previous
next