I'm currently working on a HTML / JavaScript-based Rock Paper Scissors game, starting with the good ol' Big Bang Theory "Rock Paper Scissors Lizard Spock" variant. I plan to add the rest of the variants based on James Lovelaces's variants (I suggest you look it up - it's insane.)
Anyways, there's a problem with one of the functions I'm working with to build the game. It's supposed to add a series of buttons based on an array of Strings. I'm not sure if I'm calling it wrong on the RPS5() function, or if the adoptions function is wrong, but can someone help me out here? Thank you!
Code:
var choices5 = ["Rock", "Scissors", "Lizard", "Paper", "Spock"];
function addOptions(choiceArray) {
var docFrag = document.createDocumentFragment();
for (var i = 0; i < choiceArray.length; i++) {
var elem = document.createElement('input');
elem.type = 'button';
elem.value = choiceArray[i];
docFrag.appendChild(elem);
elem.addEventListener("click", RPS5)
}
document.body.appendChild(docFrag);
}
function RPS5() {
addOptions(choices5);
}
<body onload="RPS5()">
<p id="outcome"> Outcome </p>
</body>
</html>