search

Home  >  Q&A  >  body text

"Investigation Checklist: n Options for Solving Javascript Unsorted Issues"

I'm currently trying to create a questionnaire for a website where I have a certain number of questions and a certain number of answers. But now I need to change the number of answers to different values ​​(instead of 4, but 2, 3, 5, etc.). I know nothing about website development.

Initially, I have an unsorted list:

question.innerHTML = `<h2>Q${count + 1}. ${questions[count].question}</h2>
<ul class="option_group">
<li class="option">${first}</li>
<li class="option">${second}</li>
<li class="option">${third}</li>
<li class="option">${fourth}</li>
</ul>`;

Before this, I used:

let[first, second, third, fourth] = questions[count].options;

to display options. I considered using an array to count each element of the options provided and change it for each question, but I can't seem to find the correct way to form the command. Thanks in advance for any advice!

P粉512526720P粉512526720444 days ago417

reply all(1)I'll reply

  • P粉060528326

    P粉0605283262023-09-11 10:50:16

    let html = `<h2>Q${count + 1}. ${questions[count].question}</h2>
    <ul class="option_group">`
    for (let item of questions[count].question) {
      html += `<li class="option">${item}</li>`
    }
    html += '</ul>'

    reply
    0
  • Cancelreply