I try to program the game "rock, paper, scissors" while it works, but when I want to show the winner, I can not figure out how to do it. If you look at my javascript, you will see what I tried.
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="mycss.css">
<script src="myjavascript2.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="center">
<button onclick="myFunction1()">Play</button>
<p id="rolled">You rolled:</p>
<p id="test"></p>
<p id="rolled1">Your opponent rolled:</p>
<p id="test1"></p>
<p id="test2"></p>
<p id="test3"></p>
</div>
</body>
</html>
Javascript:
var things = [ 'rock', 'paper', 'scissors'];
function myFunction1() {
var random1 = Math.floor((Math.random()*things.length));
var random2 = Math.floor((Math.random()*things.length));
document.getElementById("test").innerHTML=things[random1];
document.getElementById("test1").innerHTML=things[random2];
document.getElementById("test2").innerHTML='';
document.getElementById("test3").innerHTML='';
The image display works great.
if (random1 == random2) {
document.getElementById("test2").innerHTML="<h3>It a draw.</h3>";
}
However, it is not:
else if (random1 == 1 && random2 == 3) {
document.getElementById("test3").innerHTML="You win!";
}
} //End of myFunction1
I want to know why I cannot use this solution and what will be right. Thank.
source
share