I have a simple array
var answerAttribute = ['A','B','C','D']; I have 16 list items, what I'm trying to accomplish is loop through the length of the list and regardless of if the list 2 items or 300. I'd lke to have a data attribute associated with it of A,B, C or D.
Here's what I'm working with:
var questionOption = ''; for(var i = 0; i < quizContent.length; i++) { questionOption = answerAttribute[i % answerAttribute.length]; console.log(questionOption); } When logging this to the console, it logs A, AB, ABC, ABCD, ABCDundefined, and keeps repeating undefined until it's reached the loops conclusion. My question is what am I doing incorrectly so that it only logs one letter per loop.
<, not<=. Other than that, I don't know what your specific issue is.answerAttribute[i]should be changed toanswerAttribute[i%4]otherwise you'll getindex Out of bondif quizContent.length >3for(var i = 0; i < quizContent.length; i++) questionOption += answerAttribute[i % answerAttribute.length];but its hard to tell. Please rephrase your description...