Jump to content

[SOLVED] JS in IE "unknown runtime error"


deerly

Recommended Posts

Oh IE, you horrible pain!

 

OK so I made a HangMan game and one of the functions is to display the "guessable" string with each letter character as _ and spaces as a paragraph break.

 

This works fine in Firefox but doesn't work in IE.

 

function displayWord(){

var thisString = "";

var splitWord = word.split("");

for (var i=0; i<word.length; i++){

if(revealedPool == true){

thisString += splitWord;

}

else{

if(splitWord != " "){

thisString += " _ ";

}

else if(splitWord == " "){

thisString += "<p>";

}

}

}

document.getElementById("words").innerHTML = thisString;

}

 

The element it is supposed to be modifying is

<p><span id="words" name="words"> </span>

 

This works great in FF but while everything else seems to display OK in IE it won't show the word!

 

The error it gives me is "unknown runtime error"

 

Line: 144 (which is the innerHTML line seen above)

Char: 3

Error: Unknown runtime error

Code: 0

 

Thing is, if I hard code the values it works fine. Thanks so much for reading and helping shed some light on this!

 

Link to comment
Share on other sites

Fxed:

 

    function displayWord(){
          var thisString = "";
          var splitWord = word.split("");
          for (var i=0; i<word.length; i++){
             if(revealedPool === true){
                thisString += splitWord;
             }
             else{
                if(splitWord != " "){
                   thisString += " _ ";
                }
                else if(splitWord == " "){
                   thisString += "<p>";
                }
             }
          }
          document.getElementById("words").innerHTML = thisString;
    }

 

you were using == instead of the expected ===  ;)

 

Also as mentioned you do not define any of your variables so  it throws undefined/not found errors. ;)

Link to comment
Share on other sites

Fixed up more of the code so it stopps erroring for word since it is not a global function ;)

 

function displayWord(){
          var thisString = "one two three four";
          var splitWord = thisString.split("");
          for (var i=0; i<thisString.length; i++){
             if(revealedPool === true){
                thisString += splitWord;
             }
             else{
                if(splitWord != " "){
                   thisString += " _ ";
                }
                else if(splitWord == " "){
                   thisString += "<p>";
                }
             }
          }
          document.getElementById("words").innerHTML = thisString;
    }

Link to comment
Share on other sites

cleaned up more:

 

function displayWord(){
          var thisString = "";
          var splitWord = thisString.split("");
          for (var i=0; i<splitWord.length; i++){
             if(revealedPool === true){
                thisString += splitWord;
             }
             else{
                if(splitWord != " "){
                   thisString += " _ ";
                }
                else if(splitWord == " "){
                   thisString += "<p>";
                }
             }
          }
          document.getElementById("words").innerHTML = thisString;
    }

Link to comment
Share on other sites

Thank you so much darkfreaks!!

 

Still having some problems though  ???

 

In the first fix, the "_ _ _ _ " show up but there is no break for paragraphs for the spaces. Also, when I start to type the _ _ 's don't change to letters as it does in FireFox. (with the help of other functions)

 

In the final fix it doesn't show up again.

 

word and revealedPool are global variables and are defined by the time this function will be called.

 

I know they are defined OK because even though the word doesn't show up, all of the other functions work correctly with the invisible word so I'll get (yes that's the right letter, oops already guessed that, no thast wrong) and the hangman will be hung!

 

Something I just noticed... and I have NO IDEA how it works in FireFox! revealedPool is an array that is defined with every variable bool false! the idea is that when a letter is revealed the revealedPool[coresponding with the character in the string] will be set to true. Then it checks to see if it will display a _ if it hasnt been revealed or the letter if it has. I don't know how it was getting away with having just revealedPool instead of revealedPool but when i change it to the second suddenly it stops working in firefox!  ??? ???

 

 

Link to comment
Share on other sites

Ok :D

 

this is hm_js_functions.js

document.onkeydown = keyHit;

window.onload = initAll;

var word;

var type;

//26 letters a-z

var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value

var howHung = 0;

var revealedPool = new Array(500);

var endGame = false;

 

function initAll(){

if(document.getElementById){

//document.getElementById("reload").onclick = anotherGallow;

anotherGallow();

//newGallow();

}

else{

alert("Your browser doesn't support this script. No hang-emo for you!");

}

 

}

 

function newGallow(){

alert(word);

 

}

 

function anotherGallow(){

for(var i=0; i<letterPool.length; i++){

letterPool = false;

}

for(var i=0; i<revealedPool.length; i++){

revealedPool = false;

}

howHung = 0;

setWord();//Set the word as defined by PHP

setType();

displayWord();

displayPool();

}

 

 

function keyHit(evt){

if(!endGame){

if(evt){

var thisKey = evt.which;

}

else{

var thisKey = window.event.keyCode;

}

//alert(String.fromCharCode(thisKey));

if(thisKey >= 65 && thisKey <= 90){

birdSpeak("key");

tryLetter(thisKey);

displayPool();

//alert(String.fromCharCode(thisKey));

}

}

}

 

function tryLetter(guessed){

var poolKey = guessed - 65;

//Check to see if the letter has already been guessed

if(letterPool[poolKey]){

birdSpeak("alreadyGuessed");

birdReact("confused");

return;

}

else{

//Mark this letter as guessed.

letterPool[poolKey] = true;

var wasIn = false;

//takes the letter the user guessed and checks to see if it is in the word string

var splitWord = word.split("");

for(var i=0; i<word.length; i++){

if(splitWord.toLowerCase() == String.fromCharCode(guessed).toLowerCase()){

birdSpeak("right");

revealLetter(i);

birdReact("happy");

wasIn = true;

 

}

}

//if not, add a body part to hangman!

if(!wasIn){

howHung += 1;

birdReact("confused");

birdSpeak("wrong");

displayHanging(howHung)

}

 

 

}

 

}

 

function revealLetter(letter){

revealedPool[letter] = true;

displayWord();

checkWin();

 

}

 

function displayPool(){

var letter;

var alphaBlock = "";

for(var i=0; i<=letterPool.length; i++){

if(!letterPool){

letter = i+65;

alphaBlock += String.fromCharCode(letter);

}

}

var alpha = document.getElementById("alpha");

alpha.innerHTML = alphaBlock;

}

 

//@param int number will be 1-7, which image to display

//@param string type will determine which folder we look in for images (emo, baby, man, etc)

function displayHanging(num){

//When an incorrect letter is guessed this function will be called to add

//another piece of the hangman to the noose. 7 pieces total

document.GALLOW.src="images/" + type + "/0" + num + ".gif";

checkLoss(num);

 

}

 

function displayWord(){

    var thisString = "";

    var splitWord = thisString.split("");

    for (var i=0; i<splitWord.length; i++){

      if(revealedPool){

          thisString += splitWord;

      }

      else{

          if(splitWord != " "){

            thisString += " _ ";

          }

          else if(splitWord == " "){

            thisString += "<p>";

          }

      }

    }

    document.getElementById("words").innerHTML = thisString;

}

function checkWin(){

//Check to see if all of the letters in word have been revealed

var splitWord = word.split("");

var didWin = 0;

for (var i=0; i<word.length; i++){

if(splitWord != " "){

if(!revealedPool){

didWin += 1;

}

}

}

if(didWin == 0){

gameOver("won");

}

}

 

function checkLoss(num){

if(num >= 7){

gameOver("lose");

 

 

}

}

 

function gameOver(result){//result is either win or lose

//If the hangman is hung (reaches 7 pieces) the game is over

//Display the word with all letters revealed

//Show some kind of failure message

//Invite to create a new game

if(result == "won"){

birdSpeak("win");

birdReact("happy");

 

}

else if(result == "lose"){

for (var i=0; i<word.length; i++){

revealedPool = true;

}

displayWord();

birdSpeak("lose");

birdReact("sad");

 

}

endGame = true;

}

 

function birdSpeak(action){

if(action == "lose"){

document.getElementById("birdWord").innerHTML = "You lost :(";

}

else if(action == "win"){

document.getElementById("birdWord").innerHTML = "You won :)";

}

else if(action == "alreadyGuessed"){

document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!";

}

else if(action == "key"){

document.getElementById("birdWord").innerHTML = "What could it be?";

}

else if(action == "wrong"){

document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter";

}

else if(action == "right"){

document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!";

}

}

 

function birdReact(action){

if(action == "happy"){

document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)';

}

else if(action == "sad"){

document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)';

}

else if(action == "confused"){

document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)';

}

 

}

 

The set word and set type functions are within the .php page because they need to use PHP variables.

 

game playing page

<html>

<body>

<?php

require_once("hm_class.inc.php");

db::connect();

if(isset($_GET['g'])){

$game_in = (int)$_GET['g'];

$hint = hangman::getGameHint($game_in);

$word = hangman::getGameGuessable($game_in);

$type = hangman::getGameType($game_in);

 

}

 

?>

<script language="javascript" type="text/javascript">

function setWord(){

word = "<?php echo $word; ?>";

}

function setType(){

type = "<?php echo $type; ?>";

}

 

</script>

<LINK href="style.css" rel="stylesheet" type="text/css">

<script type = "text/javascript" src="hm_js_functions.js"></script>

<div id="body-center">

<div id="body">

<div id="header">

<div id="header-bird">

</div>

<div id="header-bird-words">

<span id="birdWord" name="birdWord">What could it be?</span>

</div>

<div id="header-hint">

<span name="hint" id="hint"><h2>

<?php

if(isset($hint)){

echo"$hint";

}

?>

</h2></span>

</div>

</div>

<div id="middle">

<div id="middle-words">

<p><span id="words" name="words"> </span>

</div>

<div id="middle-gallow">

<img id="GALLOW" name="GALLOW" src="images/gallow.gif">

</div>

<div id="middle-alpha">

<div name="alpha" id="alpha"> </div>

</div>

 

</div>

</div>

<div id="bottom">

Enjoying your game of hang-<?php echo"$type";?>?

<br><a href="hangman.php">Send a custom hang-man game to one of your friends!</a>

</div>

</div>

</body>

</html>

Link to comment
Share on other sites

Thank you so much for your patience :D I oughta buy you a beer!

 

OK so here is what I have right now for the .js file

 

document.onkeydown = keyHit;

window.onload = initAll;

var word;

var type;

//26 letters a-z

var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value

var howHung = 0;

var revealedPool = new Array(500);

var endGame = false;

 

function initAll(){

if(document.getElementById){

//document.getElementById("reload").onclick = anotherGallow;

anotherGallow();

//newGallow();

}

else{

alert("Your browser doesn't support this script. No hang-emo for you!");

}

 

}

 

function newGallow(){

alert(word);

 

}

 

function anotherGallow(){

for(var i=0; i<letterPool.length; i++){

letterPool = false;

}

for(var i=0; i<revealedPool.length; i++){

revealedPool = false;

}

howHung = 0;

setWord();//Set the word as defined by PHP

setType();

displayWord();

displayPool();

}

 

 

function keyHit(evt){

if(!endGame){

if(evt){

var thisKey = evt.which;

}

else{

var thisKey = window.event.keyCode;

}

//alert(String.fromCharCode(thisKey));

if(thisKey >= 65 && thisKey <= 90){

birdSpeak("key");

tryLetter(thisKey);

displayPool();

//alert(String.fromCharCode(thisKey));

}

}

}

 

function tryLetter(guessed){

var poolKey = guessed - 65;

//Check to see if the letter has already been guessed

if(letterPool[poolKey]){

birdSpeak("alreadyGuessed");

birdReact("confused");

return;

}

else{

//Mark this letter as guessed.

letterPool[poolKey] = true;

var wasIn = false;

//takes the letter the user guessed and checks to see if it is in the word string

var splitWord = word.split("");

for(var i=0; i<word.length; i++){

if(splitWord.toLowerCase() == String.fromCharCode(guessed).toLowerCase()){

birdSpeak("right");

revealLetter(i);

birdReact("happy");

wasIn = true;

 

}

}

//if not, add a body part to hangman!

if(!wasIn){

howHung += 1;

birdReact("confused");

birdSpeak("wrong");

displayHanging(howHung);

}

 

 

}

 

}

 

function revealLetter(letter){

revealedPool[letter] = true;

displayWord();

checkWin();

 

}

 

function displayPool(){

var letter;

var alphaBlock = "";

for(var i=0; i<=letterPool.length; i++){

if(!letterPool){

letter = i+65;

alphaBlock += String.fromCharCode(letter);

}

}

var alpha = document.getElementById("alpha");

alpha.innerHTML = alphaBlock;

}

 

//@param int number will be 1-7, which image to display

//@param string type will determine which folder we look in for images (emo, baby, man, etc)

function displayHanging(num){

//When an incorrect letter is guessed this function will be called to add

//another piece of the hangman to the noose. 7 pieces total

document.GALLOW.src="images/" + type + "/0" + num + ".gif";

checkLoss(num);

 

}

 

function displayWord(){

var thisString = "";

var splitWord = word.split("");

for (var i=0; i<word.length; i++){

if(revealedPool == true){

thisString += splitWord;

}

else{

if(splitWord != " "){

thisString += " _ ";

}

else if(splitWord == " "){

thisString += "<p>";

}

}

}

document.getElementById("words").innerHTML = thisString;

}

 

function checkWin(){

//Check to see if all of the letters in word have been revealed

var splitWord = word.split("");

var didWin = 0;

for (var i=0; i<word.length; i++){

if(splitWord != " "){

if(!revealedPool){

didWin += 1;

}

}

}

if(didWin == 0){

gameOver("won");

}

}

 

function checkLoss(num){

if(num >= 7){

gameOver("lose");

 

 

}

}

 

function gameOver(result){//result is either win or lose

//If the hangman is hung (reaches 7 pieces) the game is over

//Display the word with all letters revealed

//Show some kind of failure message

//Invite to create a new game

if(result == "won"){

birdSpeak("win");

birdReact("happy");

 

}

else if(result == "lose"){

for (var i=0; i<word.length; i++){

revealedPool = true;

}

displayWord();

birdSpeak("lose");

birdReact("sad");

 

}

endGame = true;

}

 

function birdSpeak(actions){

if(actions == "lose"){

document.getElementById("birdWord").innerHTML = "You lost :(";

}

else if(actions == "win"){

document.getElementById("birdWord").innerHTML = "You won :)";

}

else if(actions == "alreadyGuessed"){

document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!";

}

else if(actions == "key"){

document.getElementById("birdWord").innerHTML = "What could it be?";

}

else if(actions == "wrong"){

document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter";

}

else if(actions == "right"){

document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!";

}

}

 

function birdReact(actions){

if(actions == "happy"){

document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)';

}

else if(actions == "sad"){

document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)';

}

else if(actions == "confused"){

document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)';

}

 

}

 

Everything works perfectly in FF and everything works in IE *except* the "guessable message" will not display.

 

setWord() and setType() do seem to work within the game play page because in both FF and IE the hangman being displayed (with wrong selections) is correct and even in IE it does know what word is being played with because it knows what is a right/wrong letter, changes hangman image accordingly  and can detect wins/losses.

 

It now does not display any JS error in IE that I can see, it just does not display the words.  :-\

 

Link to comment
Share on other sites

Fixed used === instead of == :

 

   document.onkeydown = keyHit;
    window.onload = initAll;
    var word;
    var type;
    //26 letters a-z
    var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value
    var howHung = 0;
    var revealedPool = new Array(500);
    var endGame = false;

    function initAll(){
       if(document.getElementById){
          //document.getElementById("reload").onclick = anotherGallow;
          anotherGallow();
          //newGallow();      
       }
       else{
          alert("Your browser doesn't support this script. No hang-emo for you!");
       }
       
    }

    function newGallow(){
       alert(word);
       
    }

    function anotherGallow(){
       for(var i=0; i<letterPool.length; i++){
          letterPool = false;
       }
       for(var i=0; i<revealedPool.length; i++){
          revealedPool = false;
       }
       howHung = 0;
       setWord();//Set the word as defined by PHP
       setType();
       displayWord();
       displayPool();
    }


    function keyHit(evt){
       if(!endGame){
          if(evt){
             var thisKey = evt.which;
          }
          else{
             var thisKey = window.event.keyCode;
          }
          //alert(String.fromCharCode(thisKey));
          if(thisKey >= 65 && thisKey <= 90){
             birdSpeak("key");
             tryLetter(thisKey);
             displayPool();
             //alert(String.fromCharCode(thisKey));
          }
       }
    }

    function tryLetter(guessed){
       var poolKey = guessed - 65;
       //Check to see if the letter has already been guessed
       if(letterPool[poolKey]){
          birdSpeak("alreadyGuessed");
          birdReact("confused");
          return;
       }   
       else{
          //Mark this letter as guessed.
          letterPool[poolKey] = true;
          var wasIn = false;
          //takes the letter the user guessed and checks to see if it is in the word string
          var splitWord = word.split("");
          for(var i=0; i<word.length; i++){
             if(splitWord.toLowerCase() == String.fromCharCode(guessed).toLowerCase()){
                birdSpeak("right");
                revealLetter(i);
                birdReact("happy");
                wasIn = true;
                
             }
          }
          //if not, add a body part to hangman!
          if(!wasIn){
             howHung += 1;
             birdReact("confused");
             birdSpeak("wrong");
             displayHanging(howHung);
          }

       
       }

    }

    function revealLetter(letter){
       revealedPool[letter] = true;
       displayWord();
       checkWin();

    }

    function displayPool(){
       var letter;
       var alphaBlock = "";
       for(var i=0; i<=letterPool.length; i++){
          if(!letterPool){
             letter = i+65;
             alphaBlock += String.fromCharCode(letter);
          }
       }
       var alpha = document.getElementById("alpha");
       alpha.innerHTML = alphaBlock;
    }

    //@param int number will be 1-7, which image to display
    //@param string type will determine which folder we look in for images (emo, baby, man, etc)
    function displayHanging(num){
       //When an incorrect letter is guessed this function will be called to add
       //another piece of the hangman to the noose. 7 pieces total
       document.GALLOW.src="images/" + type + "/0" + num + ".gif";
       checkLoss(num);

    }

    function displayWord(){
          var thisString = "";
          var splitWord = word.split("");
          for (var i=0; i<word.length; i++){
             if(revealedPool === true){
                thisString += splitWord;
             }
             else{
                if(splitWord != " "){
                   thisString += " _ ";
                }
                else if(splitWord == " "){
                   thisString += "<p>";
                }
             }
          }
          document.getElementById("words").innerHTML = thisString;
    }

    function checkWin(){
       //Check to see if all of the letters in word have been revealed
       var splitWord = word.split("");
       var didWin = 0;
       for (var i=0; i<word.length; i++){
          if(splitWord != " "){
             if(!revealedPool){
                didWin += 1;
             }
          }
       }
       if(didWin === 0){
          gameOver("won");
       }
    }

    function checkLoss(num){
       if(num >= 7){
          gameOver("lose");
          

       }
    }

    function gameOver(result){//result is either win or lose
       //If the hangman is hung (reaches 7 pieces) the game is over
       //Display the word with all letters revealed
       //Show some kind of failure message
       //Invite to create a new game
       if(result === "won"){
          birdSpeak("win");
          birdReact("happy");

       }
       else if(result === "lose"){
          for (var i=0; i<word.length; i++){
             revealedPool = true;
          }
          displayWord();
          birdSpeak("lose");
          birdReact("sad");

       }
       endGame = true;
    }

    function birdSpeak(actions){
       if(actions == "lose"){
          document.getElementById("birdWord").innerHTML = "You lost ";
       }
       else if(actions === "win"){
          document.getElementById("birdWord").innerHTML = "You won ";
       }
       else if(actions ==="alreadyGuessed"){
          document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!";
       }
       else if(actions === "key"){
          document.getElementById("birdWord").innerHTML = "What could it be?";
       }
       else if(actions === "wrong"){
          document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter";
       }
       else if(actions === "right"){
          document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!";
       }
    }

    function birdReact(actions){
       if(actions === "happy"){
          document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)';
       }
       else if(actions === "sad"){
          document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)';
       }
       else if(actions === "confused"){
          document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)';
       }

    }

Link to comment
Share on other sites

Not yet  :-\

 

in IE I get the error:

 

Line 77

Char 14

Error: Object doesn't support this property or method

Code: 0

 

It displays a line of "_ _ _ _ _ _ _ _ _ " with no <p> where the space is. Does not react to key strokes at all. Same problem in firefox and IE.

 

In FF I get the error:

 

splitWord.toLowerCase is not a function

tryLetter(66)hm_js_fu...ctions.js (line 76)

keyHit(keydown charCode=0, keyCode=66)hm_js_fu...ctions.js (line 54)

[break on this error] if(splitWord.toLowerCase() ...ng.fromCharCode(guessed).toLowerCase()){

 

:-\

 

Edit: the test phrase I am using is "Biggest Loser" which should display as

_ _ _ _ _ _ _

_ _ _ _ _

 

When it starts. Then when correct letters are guessed they are filled in appropriately.

Link to comment
Share on other sites

Here is what this “toLowerCase() not a function error” really means:

 

The object you’re trying to lowercase is NOT a string object. By using

alert(typeof(object));

 

you can determine what type the JavaScript engine thinks the object is. A simple solution is:

 

object.toString().toLowerCase;

Link to comment
Share on other sites

Changing line 76 to:

            if(splitWord.toString().toLowerCase() == String.fromCharCode(guessed).toLowerCase()){

Seems to have stopped the error messages but it's still having issues displaying the word and now a bunch of new ones:

 

http://larkingabout.com/projects/HangMan/layout.php?g=111

 

The bird isn't reacting properly and telling you you've already guessed letters and when you loose and it displays the word it just repeats the string over and over again with commas.

 

Also, the alphabet pool is no longer displaying at all :(

 

It is frustrating because while I can see all of these mistakes I made, it was working in FF and now it's got all these issues that came from fixing it  ???

Link to comment
Share on other sites

Phew! Ok :)

 

Thank you for your help, I have it working again in FF but the same problem in IE!

 

  document.onkeydown = keyHit;

    window.onload = initAll;

    var word;

    var type;

    //26 letters a-z

    var letterPool = new Array(25); //Remember to add 65 to get the letter unicode value

    var howHung = 0;

    var revealedPool = new Array(500);

    var endGame = false;

 

    function initAll(){

      if(document.getElementById){

          //document.getElementById("reload").onclick = anotherGallow;

          anotherGallow();

          //newGallow();   

      }

      else{

          alert("Your browser doesn't support this script. No hang-" + type + " for you!");

      }

     

    }

 

    function newGallow(){

      alert(word);

     

    }

 

    function anotherGallow(){

      for(var i=0; i<letterPool.length; i++){

          letterPool = false;

      }

      for(var i=0; i<revealedPool.length; i++){

          revealedPool = false;

      }

      howHung = 0;

      setWord();//Set the word as defined by PHP

      setType();

      displayPool();

      displayWord();

     

    }

 

 

    function keyHit(evt){

      if(!endGame){

          if(evt){

            var thisKey = evt.which;

          }

          else{

            var thisKey = window.event.keyCode;

          }

          //alert(String.fromCharCode(thisKey));

          if(thisKey >= 65 && thisKey <= 90){

            birdSpeak("key");

            tryLetter(thisKey);

            displayPool();

            //alert(String.fromCharCode(thisKey));

          }

      }

    }

 

    function tryLetter(guessed){

      var poolKey = guessed - 65;

      //Check to see if the letter has already been guessed

      if(letterPool[poolKey]){

          birdSpeak("alreadyGuessed");

          birdReact("confused");

          return;

      } 

      else{

          //Mark this letter as guessed.

          letterPool[poolKey] = true;

          var wasIn = false;

          //takes the letter the user guessed and checks to see if it is in the word string

          var splitWord = word.split("");

          for(var i=0; i<word.length; i++){

            if(splitWord.toString().toLowerCase() == String.fromCharCode(guessed).toLowerCase()){

                birdSpeak("right");

                revealLetter(i);

                birdReact("happy");

                wasIn = true;

            }

          }

          //if not, add a body part to hangman!

          if(!wasIn){

            howHung += 1;

            birdReact("confused");

            birdSpeak("wrong");

            displayHanging(howHung);

          }

      }

 

    }

 

    function revealLetter(letter){

      revealedPool[letter] = true;

      displayWord();

      checkWin();

 

    }

 

    function displayPool(){

      var letter;

      var alphaBlock = "";

      for(var i=0; i<=letterPool.length; i++){

          if(!letterPool){

            letter = i+65;

            alphaBlock += String.fromCharCode(letter);

          }

      }

      var alpha = document.getElementById("alpha");

      alpha.innerHTML = alphaBlock;

    }

 

    //@param int number will be 1-7, which image to display

    //@param string type will determine which folder we look in for images (emo, baby, man, etc)

    function displayHanging(num){

      //When an incorrect letter is guessed this function will be called to add

      //another piece of the hangman to the noose. 7 pieces total

      document.GALLOW.src="images/" + type + "/0" + num + ".gif";

      checkLoss(num);

 

    }

 

    function displayWord(){

          var thisString = "";

          var splitWord = word.split("");

          for (var i=0; i<word.length; i++){

            if(revealedPool === true){

                thisString += splitWord;

            }

            else{

                if(splitWord != " "){

                  thisString += " _ ";

                }

                else if(splitWord == " "){

                  thisString += "<p>";

                }

            }

          }

          document.getElementById("words").innerHTML = thisString;

    }

 

    function checkWin(){

      //Check to see if all of the letters in word have been revealed

      var splitWord = word.split("");

      var didWin = 0;

      for (var i=0; i<word.length; i++){

          if(splitWord != " "){

            if(!revealedPool){

                didWin += 1;

            }

          }

      }

      if(didWin === 0){

          gameOver("won");

      }

    }

 

    function checkLoss(num){

      if(num >= 7){

          gameOver("lose");

       

 

      }

    }

 

    function gameOver(result){//result is either win or lose

      //If the hangman is hung (reaches 7 pieces) the game is over

      //Display the word with all letters revealed

      //Show some kind of failure message

      //Invite to create a new game

      if(result === "won"){

          birdSpeak("win");

          birdReact("happy");

 

      }

      else if(result === "lose"){

          for (var i=0; i<word.length; i++){

            revealedPool = true;

          }

          document.getElementById("words").innerHTML = word;

 

          birdSpeak("lose");

          birdReact("sad");

 

      }

      endGame = true;

    }

 

    function birdSpeak(actions){

      if(actions == "lose"){

          document.getElementById("birdWord").innerHTML = "You lost :(";

      }

      else if(actions === "win"){

          document.getElementById("birdWord").innerHTML = "You won :)";

      }

      else if(actions ==="alreadyGuessed"){

          document.getElementById("birdWord").innerHTML = "Oops, you have already guessed this letter!";

      }

      else if(actions === "key"){

          document.getElementById("birdWord").innerHTML = "What could it be?";

      }

      else if(actions === "wrong"){

          document.getElementById("birdWord").innerHTML = "Uh-oh, wrong letter";

      }

      else if(actions === "right"){

          document.getElementById("birdWord").innerHTML = "Good job, that was a correct letter!";

      }

    }

 

    function birdReact(actions){

      if(actions === "happy"){

          document.getElementById("header-bird").style.backgroundImage='url(images/lark/happy.gif)';

      }

      else if(actions === "sad"){

          document.getElementById("header-bird").style.backgroundImage='url(images/lark/sad.gif)';

      }

      else if(actions === "confused"){

          document.getElementById("header-bird").style.backgroundImage='url(images/lark/confused.gif)';

      }

 

    }

 

What is interesting is that it wouldn't display the alphabet pool until I moved the displayPool() above the displayWord() on lines 38 and 39. Makes me think there is something wrong with the displayWord() function still.

 

Otherwise it seems to be working again though, thank goodness!

 

http://larkingabout.com/projects/HangMan/layout.php?g=111

Link to comment
Share on other sites

I got it!!

 

The problem was that IE wasn't recognizing the

"<p>"
and switching it to
<br>
worked fine. I guess because there was no closing tag?

 

Phew, thank you so much for your patience and help! How can I mark this as solved?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.