How to wrap the radiobutton in a label?

Trying to do a little test on js. How to withdraw from solid answers to each radio button had one answer?
<div id="test">
 <button id="button">Check</button>

</div>


let test = document.querySelector('#test');

let questions = [
{
 text: '1. Voros?',
 right: 2,
 answers: ['Answer', 'Answer 2', 'Answer 3']
},
{
 text: '2. Voros',
 right: 1,
 answers: ['Answer 1', 'A2', 'A3', 'A4']
},
];

let i = 1;

for (let question of questions) {
 let div = document.createElement('div');
test.appendChild(div);

 let p = document.createElement('p');
 p.innerHTML = question.text;
div.appendChild(p);

 let form = document.createElement('form');
test.appendChild(form);
 form.dataset.right = question.right;

 let j = 0;

 for (let answer of your question.answers) {
 let input = document.createElement('input');
 input.type = 'radio';

 let label = document.createElement('label');
 label.innerHTML = question.answers;
div.appendChild(label);

 input.name = i;
 input.dataset.answerNum = j++;
form.appendChild(input);
}
i++;
}

let button = document.querySelector('#button');

button.addEventListener('click', function () {
 let forms = document.querySelectorAll('#test form');

 for (let form of forms) {
form.classList.remove('correct');
form.classList.remove('incorrect');

 let inputs = form.querySelectorAll('input');

 for (let input of inputs) {
 if (input.checked) {
 if (input.dataset.answerNum == form.dataset.right) {
form.classList.add('correct');
 } else {
form.classList.add('incorrect');
}
break;
}
}
}
});
April 3rd 20 at 17:31
0 answer

Find more questions by tags JavaScript