Edited
Sorry if the title is not clear enough. I really don't know how to describe what I ask for without an example.
The code is below.
Is it possible to fix this code so that I can use "normal" text for innerHTML? That is, labels should be as follows:
Dislike
Neither like nor dislike
Like
const negative_attitude = ['dislike', 'Dislike'];
const neutral_attitude = ['neither-nor', 'Neither like nor dislike'];
const positive_attitude = ['like', 'Like'];
const radio_buttons = [negative_attitude[0], neutral_attitude[0], positive_attitude[0]];
const checked = 'neither-nor'
radio_buttons.forEach((radioButton) => {
const input = document.createElement('input');
input.type = 'radio';
input.id = radioButton.toLowerCase();
input.name = 'attitude';
input.value = radioButton.toLowerCase();
if (radioButton.localeCompare(checked) === 0) {
input.checked = true;
}
const label = document.createElement('label');
label.innerHTML = radioButton; // How to fix?
label.htmlFor = radioButton.toLowerCase();
document.body.appendChild(input);
document.body.appendChild(label);
});
negative_attitude[0]toradio_buttons? Don't you want to addnegative_attitude? Why do you even haveradio_buttonsat all? Why not just directly accessnegative_attitude?radio_buttonsfirst.[0]element of each array intoradio_buttonsit will be['dislike', 'neither-nor', 'like']so you don't have an array of arrays.