Iterate through an Array with a for Loop please help

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

// Setup
var myArr = [ 2, 3, 4, 5, 6];
var total = 0;
for (var i= 0; i < arr.length; ++i) {

total += myArray[i];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36

Challenge: Iterate Through an Array with a For Loop

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

1 Like

I don’t exactly know what the issue is here, but try writing i++ instead of ++i and see if it helps.
Happy coding!

Pre and postfix of ++ should have identical behavior in this case.

1 Like

I tried it but still giving me problems.

@JeremyLT thank you very much for the correction!

@siba45, you have initialized an array named myArr. Then, in the for statement you call the length method on something named arr. Then, you calculate the total on myArray.
If what you posted is all the code, neither arr nor myArray are initialized.
If you want to calculate the total on myArr, try changing the other two names to this one.

I saw it just now and it worked thanks! :grinning: :grinning: :grinning: :grinning:

can you also help me with word blanks I’m having issues there i have already posted it few days later it won’t allow me to post same topic again

If you are having issue with wordblanks still you should reply to the original post here.

That way it will bump up to the top of the recent posts in the forum and people can see it and help out.


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