Count Backwards With a For Loop Exercise

Count Backwards With a For Loop Exercise
0

#1

I know it is really simple question but the exercise doesn’t let me pass it through. Is it something from my syntax? I couldn’t find it and that is my second odd question that I couldn’t pass. Thanks guys.


#2

Your current code creates the the array [ 9, 6, 3 ]. Why?

Because you start with j = 9 and continue until j = 0 at which point the for loop condition of j > 1 is no longer true.

First iteration where j = 9, since 9 is > 1, you push 9 into myarray.

Second iteration starts with j = 6, because your end expression j -= 3 subtracts 3 from 9 and assigns the result back to j. Since 6 is > 1, you push 6 into myarray.

Third iteration starts with j = 3, because your end expression j -= 3 subtracts 3 from 6 and assigns the result back to j. Since 3 is >1, you push 3 into myarray.

Final iteration attempt starts with j = 0, because your end expression j -=3 subtracts 3 from 3 and assigns the result back to j. Since 0 is not greater than 1, nothing happens and the for loop ends.

In the future, please use the Ask for Help button when asking a question about a new challenge, because it will automatically post the code for us to review instead of you having to post a screenshot.