Skip to content
Advertisement

How I can show the correct and incorrect answer at the moment of selection and the number of correct answers a person selected in my mcq website?

I got the code for my MCQ website. But when the user selects an option, I want to shows the correct and incorrect answer at the moment of selection (That is when the user selects the correct option, then the option will be highlighted. but when the user selects an incorrect option, I want to show that it is incorrect and along with that correct answer also showed). And also there is no second chance is given to the user for selecting the option which already showed the correct answer. (In such case the user can select the correct answer shown and it will be also “counted as the correct answer”). The code is below.

JavaScript

Advertisement

Answer

You are using 1 version of jQuery… update to 3.5.1

Replace this line:

JavaScript

with this one:

JavaScript

“I want to show that it is incorrect and along with that correct answer also showed).”

For this it is necessary at the end of each function that is responsible for incorrect answers to call the function for correct answer.

We call the function with added argument. If the argument is “true” displayAnswer11(true), it add value to the result. If the argument is “false” displayAnswer11(false) it marks the correct answer but does not add value to the result.


Example:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement