I am having a very hard time with this game. i can get the userChoice image to display, and the computerChoice image to display, but i cannot get the checkWinLoseTie() function to work. but i am unsure WHY it isnt working. are my arguments wrong (i know there is something wrong, but cannot get it right!), are the variables even getting assigned a value?
i keep getting the message "you lost" which means that the rest of the stuff is not running!
please help me, this is driving me nuts! i've been working on this for the last 2-3 weeks and have been stuck on this part for 10 days trying to work it out.
here is my code:
this is my other code (ive been trying to get either or to work! cant figure out which one woudl be best)
i keep getting the message "you lost" which means that the rest of the stuff is not running!
please help me, this is driving me nuts! i've been working on this for the last 2-3 weeks and have been stuck on this part for 10 days trying to work it out.
here is my code:
Code:
<html> <head> <script> var computerChoice; var userChoice; function computerChoose() { computerChoice = Math.floor(Math.random()*3)+1; if (computerChoice == 1) { document.computerImage.src = "rock.jpg"; } else if (computerChoice == 2) { document.computerImage.src = "paper.jpg"; } else { document.computerImage.src = "scissors.jpg"; } } function userChoose(userChoice) { if (userChoice == 1) { document.userImage.src = "rock.jpg"; } if (userChoice == 2) { document.userImage.src = "paper.jpg"; } if (userChoice == 3) { document.userImage.src = "scissors.jpg"; } } function checkWinLoseTie() { if (userChoice == computerChoice) { document.gameForm.userDraws.value = parseInt(document.gameForm.userDraws.value) + 1; alert("That's a Tie!"); } if ((userChoice == 2 && computerChoice == 1)||(userChoice == 3 && computerChoice == 2)||(userChoice == 1 && computerChoice == 3)) { document.gameForm.userWins.value = parseInt(document.gameForm.userWins.value) + 1; alert("You Won!"); } else { document.gameForm.userLosses.value = parseInt(document.gameForm.userLosses.value) + 1; alert("Sorry, You Lost!"); } } function playGame() { computerChoose(); checkWinLoseTie(); } </script> </head> <body> <img name="userImage" src="" width 70 height=70><img name="computerImage" src="" width=70 height=70><br> <form name="gameForm"> You Choose:<input type=button value="Rock" onClick=' var userChoice = 1; document.userImage.src = "rock.jpg"; '> <input type=button value="Paper" onClick=' var userChoice = 2; document.userImage.src = "paper.jpg"; '> <input type=button value="Scissors" onclick=' var userChoice = 3; document.userImage.src = "scissors.jpg"; '><br> <input type = button value = "Play!" onclick = "playGame()"><br> Wins:<input type = text name = "userWins" value = "0"><br> Losses:<input type = text name = "userLosses" value = "0"><br> Draws:<input type = text name = "userDraws" value = "0"> </form> </body> </html>
this is my other code (ive been trying to get either or to work! cant figure out which one woudl be best)
Code:
<html> <head> <script> var computerChoice; var userChoice; function computerChoose() { computerChoice = Math.floor(Math.random()*3)+1; if (computerChoice == 1) { document.computerImage.src = "rock.jpg"; } else if (computerChoice == 2) { document.computerImage.src = "paper.jpg"; } else { document.computerImage.src = "scissors.jpg"; } } function userChoose(userChoice) { if (userChoice == 1) { document.userImage.src = "rock.jpg"; } if (userChoice == 2) { document.userImage.src = "paper.jpg"; } if (userChoice == 3) { document.userImage.src = "scissors.jpg"; } } function checkWinLoseTie() { var userChoice; var computerChoice; if (userChoice == computerChoice) { draw(); } if ((userChoice == 2 && computerChoice == 1)||(userChoice == 3 && computerChoice == 2)||(userChoice == 1 && computerChoice == 3)) { win(); } else { loss(); } } function draw() { document.gameForm.userDraws.value = parseInt(document.gameForm.userDraws.value) + 1; alert("That's a Tie!"); } function win() { document.gameForm.userWins.value = parseInt(document.gameForm.userWins.value) + 1; //alert("You Won!"); } function loss() { document.gameForm.userLosses.value = parseInt(document.gameForm.userLosses.value) + 1; alert("Sorry, You Lost!"); } function playGame() { computerChoose(); checkWinLoseTie(); } </script> </head> <body> <img name="userImage" src="" width 70 height=70><img name="computerImage" src="" width=70 height=70><br> <form name="gameForm"> You Choose:<input type=button value="Rock" onClick=' var userChoice = 1; document.userImage.src = "rock.jpg"; '> <input type=button value="Paper" onClick=' var userChoice = 2; document.userImage.src = "paper.jpg"; '> <input type=button value="Scissors" onclick=' var userChoice = 3; document.userImage.src = "scissors.jpg"; '><br> <input type = button value = "Play!" onclick = "playGame()"><br> Wins:<input type = text name = "userWins" value = "0"><br> Losses:<input type = text name = "userLosses" value = "0"><br> Draws:<input type = text name = "userDraws" value = "0"> </form> </body> </html>
Comment