How can I retrieve the value of the button? the value is always different
Let's say
newArr = [1,2,3,4,5,"A","B","C","D","E"]
The 3 buttons will always have different value, how can I retrieve it? I need the value because I need to do a score system when user choose on the correct button, therefore I need to know what is the value in the button that the user click to determine if the user is able to score a point or deduct points.
This is to random generate a value to put into the button
var index1 = newArr[Math.floor(Math.random()*newArr.length)];
document.getElementById("TO1").value = index1;
var Arr2 = newArr.splice(index1, 1);
//enter random element into Option 2
var index2 = newArr[Math.floor(Math.random()*newArr.length)];
document.getElementById("TO2").value = index2;
var Arr3 = newArr.splice(index2, 1);
//enter random element into Option 3
var index3 = newArr[Math.floor(Math.random()*newArr.length)];
document.getElementById("TO3").value = index3;
<html>
<input type="button" class="gameOpt" id="TO1" value="Option 1" >
<input type="button" class="gameOpt" id="TO2" value="Option 2" >
<input type="button" class="gameOpt" id="TO3" value="Option 3" >
</html>
I am using this in the script, but I am sure this is not working
var option1 = document.getElementById("TO1").value;
var option2 = document.getElementById("TO2").value;
var option3 = document.getElementById("TO3").value;
document.getElementById("TO1")andindex1?index 1, i get the value of what is displayed on the button, fordocument.getElementById("TO1")i don't get anything when iconsole.logit