1

Javascript/JQuery

    var gallerynr = 3;
    var thumbsnrA = new Array(gallerynr);

    var a = 0;
    var b = 0;
    var d = 0;

    for (d = 0; d == gallerynr; d++) {
        thumbsnrA[a] = 22;
        a ++;
        b ++;
    };

    alert(thumbsnrA);

Result (should be):

22,22,22

But my Result is:

,,

What is wrong with the syntax of my code?

3 Answers 3

7

You test is wrong.

for (d = 0; d < gallerynr; d++) {

is what you want

If you have

for (d = 0; d == gallerynr; d++) {

it only runs when d is 3 and it is not 3 from the beginning

Sign up to request clarification or add additional context in comments.

Comments

0

Your array variable is declared as thumbsnr, but you reference thumbsnrA later on in the code.

Edit - OK, so you've changed your code! There is a misplaced semi-colon after your loop - that could be throwing the error.

1 Comment

yeah I saw that typo here after posting it - im sorry
0

You don't need a delimiter after the closing brace of the for loop, and if d!=gallerynr before the loop, then the for loop will never be entered.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.