Can you help with quiz app?

I’m working on a quiz app that randomly selects questions from a javascript object. The main problem I am having is that I want to reassign classes of the new choices when they come into the new page but I can’t get them to reassign. The code uses an unsavory mix of jQuery and plain javascript, which I’m planning on cleaning up once the logic is in place. Can anyone help me figure out what is going wrong with assigning new classes to the new questions? I’m not quite sure how to point to the “correct” elements in the object.

Codepen link here.

Here is the problem area:

    function correct() {
    	for (i=0; i < choices.length; i++) {
    	if (choices[i] === choices[correct])
    		$(this).parent().addClass("correct");
    	}
    }

function incorrect() {
	for (i=0; i < choices.length; i++) {
	if (choices[i] !== choices[correct])
		$(this).parent().addClass("wrong");
	}
}

There are more problem areas in your code. Here’s my attempt at fixing your code without completely rewriting it (I added styling to the correct answer for visibility):

1 Like

Thanks for taking the time to fix the major problems with this code. I’m still learning and I really appreciate your help!