Skip to content
Advertisement

How random option catch correspondent number?

JavaScript
JavaScript
JavaScript

How random option catch correspondent number ?

For example:

  • If question random option is (4) (2) (3) (1) arrangement

  • Answer should be (1),because set class=”correct” in question1 option1 but in the case (1) is X (wrong answer).

I guess it get <div> position, so array and real number not match.

What’s wrong with my code?

Advertisement

Answer

Your are fixing correct class on theses positions. Add correct when generate random values:

JavaScript

Live example with dynamic positions:

JavaScript
JavaScript
JavaScript

Perhaps in addition to dynamic positions for improvement you can also put dynamic responses instead of 1 for question 1 and 2 for question 2:

A simple adjustment can do it:

JavaScript

With simple helper function:

JavaScript
Advertisement