I\'m learning javascript and I decided to create simple Rock, Paper, Scissors game. I want to make it controllable by buttons. So I made this in html:
The other answers are fixing some issues. There is also a problem with the way you're calling the functions as you're passing rock
as a variable, you need to use a string:
<button onClick="user('rock')">Rock</button>
Unless you're declaring the variables somewhere but it's not shown in your code.
Maybe try this.. cleaner markup.. uses jQuery
<div id="game">
<button class="user" data-name="rock">Rock</button>
<button class="user" data-name="paper">Paper</button>
<button class="user" data-name="scissors">Scissors</button>
<div id="result"></div>
<br>
<br>
<button id="test">DEBUG</button>
</div>
$(document).ready(function() {
var user = "none";
$(".user").click(function() {
user = $(this).attr("data-name");
});
$("#test").click(function() {
alert(user);
});
});
http://jsfiddle.net/rQDbe/