Kinda confuse how this two for loop works here

    for (var j = 1; j < answersCopy.length; j++){
        var rand = Math.floor(Math.random() * (index - 1)) + 1;
        index -= 1;
// here like it goes back to temp.
        var temp = answersCopy[index];
        answersCopy[index] = answersCopy[rand];
        answersCopy[rand] = temp;

    // Swap the correct answer into the target location
    for (i = 0; i < ANSWER_COUNT; i++) {
        answers[i] = answersCopy[i];

// here it also go  back to temp....
    temp = answers[0];
    answers[0] = answers[correctAnswerTargetLocation];
    answers[correctAnswerTargetLocation] = temp;
    return answers;


I really see no question here, at least with me, you kind of have to be so specific about what you want to know that answers fall out almost on their own


OK my fault my mistake,

it’s about the var temp, and the loop goes

temp = answersCopy[index] // index by the way is = to answersCopy.length; is also equals to = 3
answers[index]= etc…
then it goes back to temp.

my question is what is the idea or the purpose of this section of the code

also it’s the same with getting the correctAnswerTargetLocation,

like how does the computer know that that is the right answer,

and the answers[correctAnswerTargetLocation] = temp; is = to the 3 answers of every question.

after this code here there is no other code that will help understand the Computer that every set of question has a different set of answer’s (it is not always the number 3 answers)


The computer knows nothing, code is a series of steps to carry out.

To understand your piece of code, you’d either ask the author, or ask them to write more obvious code, or learn more so that you can read increasingly difficult code

Everything there is made out of simple things like assignments, array lookup, functions, loops… You should probably know what all of that does, and then it’s just a matter of reading the steps and trying to fit a purpose to those steps

What’s the purpose of this?

stand at the purple rock
face north
walk five steps forwards
turn left
walk three steps backwards

Pirate treasure? Who knows. Maybe me, the author.


ionatan, thank you so much and I’ll do my best to di-cypher the code
also thank you so much for the time and Attention on my post

Much love and Be Blessed :sunny:

~KC. Diez


Can’t tell if you’re actually accepting my non-answer or just giving up.

But that’s really how it goes. You read it and you might or might not see what it’s good for, and hopefully there’s a description somewhere about what it’s supposed to do and how to use it (documentation), or maybe it wasn’t even meant for your eyes, but if you do a bit of detective work you might make sense out of it just the same.

But like with the pirate map thing, the operations should all be making sense to you, and if not, then those are what to learn

You might for example go stand at the purple rock and carry out the steps and watch what happens


No way man this is exciting for me,

i just need some help on maybe I’m doing it wrong on understanding it but it turn’s out I’m actually in the right direction,

I just need to break the code down into single little pieces maybe from there I might get the perspective on what is actually happening,

thank’s again ionatan.

Be Blessed :sunny:

~K.C, Diez


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.