Why are neither functions getting called if one of them is uncommented?

ttiimmoo

New Member
I have an external javascript file that has two functions and both should be called every time the page loads.However, neither do. If I comment out the line in the js file that calls the tester() function, then runGame() is called, but if tester() is not commented, then neither run.However, if I put the tester() function call after the runGame() call, then runGame() works, but tester() still doesn't work.tester() doesn't even run by itself, so there's probably something I did wrong in that function. Can anyone tell me what I did wrong?html\[code\]<html><head> <script type="text/javascript" src="http://stackoverflow.com/questions/15652023/rock_paper_scissors.js"> </script></head><body> <p id="game">Test</p> <br /> <input type="button" value="http://stackoverflow.com/questions/15652023/Play again" onClick="tester()"></input></body>\[/code\]rock_paper_scissors.js\[code\]var info = document.getElementById("game");var tester = function(){ document.getElementById('game').innerHTML = 'hello'; //info.innerHTML("HI");};var compare = function(choice1, choice2){ if(choice1 == choice2) document.write("The result is a tie!"); else if(choice1 == "rock"){ if(choice2 == "scissors") document.write("You win! Rock wins"); else document.write("The computer wins! Paper wins"); } else if(choice1 == "paper"){ if(choice2 == "rock") document.write("You win! Paper wins"); else document.write("The computer wins! Scissors wins"); } else if(choice1 == "scissors"){ if(choice2 == "rock") document.write("The computer wins! Rock wins"); else document.write("You win! Scissors wins"); } else document.write("You didn't pick a real choice");};var runGame = function(){ var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); if (computerChoice < 0.34) { computerChoice = "rock"; } else if(computerChoice <= 0.67) { computerChoice = "paper"; } else { computerChoice = "scissors"; } document.write("<p>You picked " + userChoice + "</p>"); document.write("<p>The Computer picked " + computerChoice + "</p>"); compare(userChoice, computerChoice);};runGame();tester();\[/code\]
 
Back
Top