Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Roy Van den Brande
Roy Van den Brande
10,926 Points

Get value in array by increments of three

I'm trying to write a calculator that uses a calculation of the number of months to get a value in an array. The problem is two-fold:

  1. For the first 2 years, I move an extra space in the array for each start of the 3th month (so 0=array[0], 3=array[1], 6=array[2],... After that it changes each year, so 12 months to move through the next array value. I started to write if else statements for every value between two numbers but I was hoping a for loop for the first 2 years and one for the other 38 years could help me loop throught them.

        /*for loop until 24 months (from then each year)*/
        for(aEenheidsstatuut < 24) {};
            /*get value from array*/
        /*for loop from 24 months up to 480 months*/
        for (aEenheidsstatuut >= 24) {};
            /*get value from array*/
    
  2. When I get the for loop, how do I write the statement in the first one to get to every third month (for example round down to number divisable by 3?) and make echt next number get to the next array. And in the second case each number rounded down divisable by 12.