-1

I'm creating a multiple choice quiz which allows users to insert their own questions and answers and from there create a quiz. I can't think how I could let users delete questions stored in the question bank.

    bodyText = bodyText + '<p>Questions currently in the question bank:</p>';
    bodyText = bodyText + '<ul>';
    for(var i=0; i<questionBank.length;i++) {
        // loop through the quiz bank and display each question text for review
        bodyText = bodyText + '<li>' + questionBank[i]['questionText'] + '</li>';
    }
    bodyText = bodyText + '</ul>';
    bodyText = bodyText + '<p>Create the quiz, delete or add more questions. </p>';
}
Arun Vinoth
  • 20,360
  • 14
  • 48
  • 135
vZeqk_
  • 23
  • 6
  • take a look at https://stackoverflow.com/q/5767325/3755692 – msrd0 Dec 19 '17 at 00:47
  • Why would you want someone to answer their own questions? Are you wanting others to take their quiz? You'll want to use a Sever Language for that. – StackSlave Dec 19 '17 at 01:28

1 Answers1

0

If you also create a button to attached an action too, you can capture the [i] and use it to splice, remove, push, pop, whichever you choose.

bodyText = bodyText + '<p>Questions currently in the question bank:</p>';
    bodyText = bodyText + '<ul>';
    for(var i=0; i<questionBank.length;i++) {
        // loop through the quiz bank and display each question text for review
        bodyText = bodyText + '<li>' + questionBank[i]['questionText'] + '</li>'
         <button onClick={delete questionBank[i]}>Delete me</button>;
    }
    bodyText = bodyText + '</ul>';
    bodyText = bodyText + '<p>Create the quiz, delete or add more questions. </p>';
}

my button is sudo code!!! It sounds like you might be new to programming, have fun with this. The basic idea is inside that for loop, you can use the [i] or index for each item you're rendering.

Gavin Thomas
  • 1,702
  • 8
  • 16