function alphaPanel() {
// Reference the <form>
var gallows = document.forms[0];
// Create a <fieldset>
var set = document.createElement('fieldset');
// Make an array of 26 strings
var alphaArray = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
/* Start at 0;
|| For every loop...
|| ...Create a <label>...
|| ...Create an <input>...
|| ...Make <input> a [checkbox] type...
|| ...Assign <[check]> the value of i as indexed in alphaArray.
|| ...Add text to <label> with the value of i as indexed in alphArray.
|| ...Append <[check]> to <label>...
|| ...Append <label> to <fieldset>...
|| ...Continue doing this loop 25 more times
|| ...After the 26th loop is completed...
|| ...Append <fieldset> to <form>
*/
for (let i = 0; i < 26; i++) {
var label = document.createElement('label');
var check = document.createElement('input');
check.setAttribute('type', 'checkbox');
check.value = alphaArray[i];
label.textContent = alphaArray[i];
label.appendChild(check);
set.appendChild(label);
}
gallows.appendChild(set);
}
// An empty array to store the player's picks
var picked = [];
// When a change event occurs in <form> call alphaData()
gallows.addEventListener('change', alphaData, false);
/* If the node <[check]> is not...
|| ...the current node on the event chain...
|| ...then it's is the node that was clicked.
|| Store that node's value and then...
|| ...add it to the array picked.
*/
function alphaData(event) {
if (event.target !== event.currentTarget) {
var target = event.target;
var pick = target.value;
picked.push(pick);
}
console.log('Player has picked: ' + picked.toString());
}
// Call alphaPanel()
alphaPanel();
input[type='checkbox'] {
width: 3ch;
height: 3ex;
}
label {
border: 1px solid grey;
padding: 3px;
line-height: 1.6;
}
<form id='gallows' name='gallows'></form>