I am learning javascript and I decided to create a simple Rock, Paper, Scissors game. I want to make it button-driven. So I did it in html:
<div id="game"> <button onClick="user(rock)">Rock</button> <button onClick="user(paper)">Paper</button> <button onClick="user(scissors)">Scissors</button> <div id="result"></div> <br> <br> <button onClick="test()">DEBUG</button> </div>
and this is in the .js file.
var user = "none"; function user(choice){ var user = choice; } function test(click){ alert("You chose " + user); }
So, I thought that after I click the Rock button, it will change the user var to rock, but thatβs not the case. After I click rock and then the Debug button, I get "You have not selected anything."
Kyrbi source share