<div id="container"></div>
const container = document.getElementById('container');
const options = [
['QnA', 'ru', 'google'],
['habr', 'stackoverflow', 'com'],
['ru', 'com', '/search'],
];
let index = 0;
const userChoices = [];
const makeSelect = opts => {
const select = document.createElement('select');
select.name = 'example';
const option = document.createElement('option');
option.disabled = 1;
option.hidden = 1;
option.selected = 1;
option.value = null;
option.innerText = 'Make a choice:';
select.appendChild(option);
opts.forEach(opt => {
const option = document.createElement('option');
option.value = opt;
option.innerText = opt;
select.appendChild(option);
});
return select;
};
const onSelect = ({ target }) => {
userChoices.push(target.value);
step();
};
const step = () => {
while (container.children.length) {
container.children[0].remove();
}
const select = makeSelect(options[index]);
index = ++index % options.length;
select.addEventListener('input', onSelect);
container.appendChild(select);
const p = document.createElement('p');
p.innerText = userChoices.join('.');
container.appendChild(p);
};
step();
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.