vendredi 1 novembre 2019

I cant make my if statement work in simple jquery quiz

Beginner in programming here...

I am trying to make this work, but so far no luck... I looked but havent got the terminology to find the answer on www.

if (selections[i] === triviaQuestions[currentQuestion-1].correctSelection) {

I suppose the problem is with selection[i] part since I can make it work with other statements.

Here is how its made: var selections = triviaQuestions[currentQuestion].selection; console.log("selections " +selections);

So it contains an array: var triviaQuestions = [ { question: "아", selection: [" A ", " B/P ", " EO ", " K " ], correctSelection: "A" },

Reason I want the selection[i] is that I am using it to loop through the array like this:

for (var i = 0; i < selections.length; i++) {

I have output the ingredients to console to check them and they do give the same output there!

console.log("selected: " +selections[i]); console.log("Correct: " + triviaQuestions[currentQuestion-1].correctSelection );

Aucun commentaire:

Enregistrer un commentaire