I do not understand why this code does not work? It will show ????? for the word length, but will does not actually access the individual letters within the word list. I enter the vowels as guesses, and NONE of the vowels are said to be in the word. I'm trying to put the working code in a separate JS file, instead of having the silly thing on the same HTML page. This might allow me to incorporate user choosing which game to play within the same HTML page, if my other support issue gets resolved.
Thanks!
ps. The code appears to work if I have the JS on the same page as the HTML.
Erroroneous JS code
The HTML code:
Thanks!
ps. The code appears to work if I have the JS on the same page as the HTML.
Erroroneous JS code
Code:
//characters can not be longer than 16 letters because browser will not show it.
var can_play = true;
var words = new Array("waschbecken","toilette","seife","badewanne","wasserhahn","handtuch","dusche","waschlappen","toilettenpapier","wasser","zahnpasta","zahnbürste");
var to_guess = "";
var display_word = "";
var used_letters = "";
var wrong_guesses = 0;
function selectLetter(l)
{
if (can_play == false)
{
return;
}
if (used_letters.indexOf(l) != -1)
{
return;
}
used_letters += l;
document.game.usedLetters.value = used_letters;
if (to_guess.indexOf(l) != -1)
{
// correct letter guess
pos = 0;
temp_mask = display_word;
while (to_guess.indexOf(l, pos) != -1)
{
pos = to_guess.indexOf(l, pos);
end = pos + 1;
start_text = temp_mask.substring(0, pos);
end_text = temp_mask.substring(end, temp_mask.length);
temp_mask = start_text + l + end_text;
pos = end;
}
display_word = temp_mask;
document.game.displayWord.value = display_word;
if (display_word.indexOf("?") == -1)
{
// won
alert("You've saved the Book from Evaporation! Congratulations, Mazel Tov and all that good stuff!");
can_play = false;
}
}
else
{
// incorrect letter guess
// 12 guesses
wrong_guesses += 1;
eval("document.hm.src=\"/gaming/2/word/evapbook/12/" + "hm" + wrong_guesses + ".gif\"");
if (wrong_guesses == 12)
{
// lost
alert("Oh no! The Book is evaporating! Please try again!");
can_play = false;
}
}
}
function reset()
{
selectWord();
document.game.usedLetters.value = "";
used_letters = "";
wrong_guesses = 0;
document.hm.src="/gaming/2/word/evapbook/12/hmstart.gif";
var links = document.getElementsByTagName("a");
for (i = 0; i < links.length; i++) {
links[i].style.color = "#0000ff";
}
}
function selectWord()
{
can_play = true;
random_number = Math.round(Math.random() * (words.length - 1));
to_guess = words[random_number];
//document.game.theWord.value = to_guess;
// display masked word
masked_word = createMask(to_guess);
document.game.displayWord.value = masked_word;
display_word = masked_word;
}
function createMask(m)
{
mask = "";
word_length = m.length;
for (i = 0; i < word_length; i ++)
{
mask += "?";
}
return mask;
}
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="utf-8">
<head>
<title> Scrambled Words </title>
<META http-equiv="expires" content="Thur, 1 March 2007 13:00:00 GMT">
<meta http-equiv="Content-Type" content="text/html charset=utf-8">
<link type="text/css" rel="stylesheet"
href="http://www.globalwritersclub.com/gaming/2/word/scrambled/css/scrambled.css">
<script language="Javascript" src="http://www.globalwritersclub.com/gaming/2/word/evapbook/eb/de/js/1a.js"></script>
<!-- script originally by Chris Fortey @ http://www.c-g-f.net -->
</HEAD>
<body onLoad="reset(); return true;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" Summary="NAV TABLE">
<tr>
<td class="tcp">
<br>
The Book Rescue
<br>
Plug in your guesses below!<br>
You have 12 guesses.
<br> <br>
<!--THE SCRIPT THAT HE USES-->
<img src="/gaming/2/word/evapbook/12/hmstart.gif" height="230" width="266" name="hm" alt="Image used to display stages of errors.">
<form name="game">
<p><center>
Display Word: <input type="text" name="displayWord"><br>
Used Letters: <input type="text" name="usedLetters"> </center></p>
</form>
<p><center>
<a href="javascript:selectLetter('A');" onclick="this.style.color='#ff0000'">A</a> |
<a href="javascript:selectLetter('Ä');" onclick="this.style.color='#ff0000'">Ä</a> |
<a href="javascript:selectLetter('B');" onclick="this.style.color='#ff0000'">B</a> |
<a href="javascript:selectLetter('C');" onclick="this.style.color='#ff0000'">C</a> |
<a href="javascript:selectLetter('D');" onclick="this.style.color='#ff0000'">D</a> |
<a href="javascript:selectLetter('E');" onclick="this.style.color='#ff0000'">E</a> |
<a href="javascript:selectLetter('F');" onclick="this.style.color='#ff0000'">F</a> |
<a href="javascript:selectLetter('G');" onclick="this.style.color='#ff0000'">G</a> |
<a href="javascript:selectLetter('H');" onclick="this.style.color='#ff0000'">H</a> |
<a href="javascript:selectLetter('I');" onclick="this.style.color='#ff0000'">I</a> |
<a href="javascript:selectLetter('J');" onclick="this.style.color='#ff0000'">J</a> |
<a href="javascript:selectLetter('K');" onclick="this.style.color='#ff0000'">K</a> |
<a href="javascript:selectLetter('L');" onclick="this.style.color='#ff0000'">L</a>
<a href="javascript:selectLetter('M');" onclick="this.style.color='#ff0000'">M</a>
<a href="javascript:selectLetter('N');" onclick="this.style.color='#ff0000'">N</a> | <br />
<a href="javascript:selectLetter('O');" onclick="this.style.color='#ff0000'">O</a> |
<a href="javascript:selectLetter('Ö');" onclick="this.style.color='#ff0000'">Ö</a> |
<a href="javascript:selectLetter('P');" onclick="this.style.color='#ff0000'">P</a> |
<a href="javascript:selectLetter('Q');" onclick="this.style.color='#ff0000'">Q</a> |
<a href="javascript:selectLetter('R');" onclick="this.style.color='#ff0000'">R</a> |
<a href="javascript:selectLetter('S');" onclick="this.style.color='#ff0000'">S</a> |
<a href="javascript:selectLetter('T');" onclick="this.style.color='#ff0000'">T</a> |
<a href="javascript:selectLetter('U');" onclick="this.style.color='#ff0000'">U</a> |
<a href="javascript:selectLetter('Ü');" onclick="this.style.color='#ff0000'">Ü</a> |
<a href="javascript:selectLetter('V');" onclick="this.style.color='#ff0000'">V</a> |
<a href="javascript:selectLetter('W');" onclick="this.style.color='#ff0000'">W</a> |
<a href="javascript:selectLetter('X');" onclick="this.style.color='#ff0000'">X</a> |
<a href="javascript:selectLetter('Y');" onclick="this.style.color='#ff0000'">Y</a> |
<a href="javascript:selectLetter('Z');" onclick="this.style.color='#ff0000'">Z</a> </center> </p>
<p>
<a href="javascript:reset()">Start game / Reset game</a></p>
</table>
</body>
</html>
Comment