Cant find the mistake

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

Your code so far

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

// Only change code below this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 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.

I am seeing a few problems off the bat:

  1. You are not adding anything together
  2. You are using total as your loop variable instead of using it to hold a sum
  3. You have have an ‘off by one’ problem in your for loop bounds

You should get in the habit of describing your problem - sometimes just figuring out how to explain it will give insight.

In any case:

for(var total = 0 ;total >= myArr.length;total++ ){

You have a couple of issues here:

First of all, are you sure total is what you want to use for your control variable? Usually we use something like “i” for the control variable. You can use other things, but “total” doesn’t make sense here. That should be used for the sum of the numbers, not a counting variable to keep track of which element you are adding.

The other problem is that I think you need to rethink total >= myArr.length - even if you change it to the right variable, I think the logic is wrong.

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