I wonder how can I automate and ease javascript code. For example, I have got 3 buttons:
<button id="rock" class="pick" value="rock">rock</button>
<button id="paper" class="pick" value="paper">paper</button>
<button id="scissors" class="pick" value="scissors">scissors</button>
And I select these elements 3 times. So my question is how can I make it in just one instruction or function?
var userInput = '';
document.getElementById('rock').onclick = function() {
userInput = 'rock';
}
document.getElementById('paper').onclick = function() {
userInput = 'paper';
}
document.getElementById('scissors').onclick = function() {
userInput = 'scissors';
}
I just wonder if I can make something like this:
document.getElementById(element).onclick = function() {
userInput = element.value;
}