Comparing arrays with source questions and user answers
This is not much of a code review answer, but I don't have time for more right now :(

Here's a stripped down version using only arrays for answers, with indexes (zero to four) as the question numbers. Essentially, it seems like much of your object structures aren't needed at all.



const correctAnswers = [1,4,2,1,3]

const userAnswers = [1,1,1,1,1]

const countRightAnswers = answers =&gt; answers.filter((a, i) =&gt; a == correctAnswers[i]).length

const indexOfRightAnswers = answers =&gt; answers.map((a, i) =&gt; a == correctAnswers[i] ? i : -1).filter(i =&gt; i &gt; -1)

console.log(countRightAnswers(userAnswers))
console.log(indexOfRightAnswers(userAnswers))


Try it online!