Changing variable by html button
<div id="game">
<button onClick="choose('rock')">Rock</button>
<button onClick="choose('paper')">Paper</button>
<button onClick="choose('scissors')">Scissors</button>
<div id="result"></div>
<br>
<br>
<button onClick="test()">DEBUG</button>
</div>
and
var user;
function choose(choice){
user = choice;
}
function test(click){
alert("You chose " + user);
}
var
is used for declaring a variable. You don't need to declare user
variable again in user
function. You just need to assign a value to declared one.
var user; //declaration
function user(choice) {
user = choice; //assignment
}
One problem:
var user = "none";
function user(choice){
var user = choice;
}
One variable of user is hiding the other variable of user.
And having a function and variable with the same name is a BAD idea.