Indexing and increment on for loop

Tell us what’s happening:

On the first iteration of the code below, does “i” index as it’s declared value of “0” or does it index as “1” because of the increment? Is the value of “i” only incremented after the first iteration is executed? For example: on the first round is it “product *= arr[0]” or “product *= arr[1]”

Your code so far

     function multiply(arr, n) {
    var product = 1;
    for (var i = 0; i < n; i++) {
        product *= arr[i];
    return product;

function sum(arr, n) {
// Only change code below this line

// Only change code above this line

Your browser information:

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

Challenge: Replace Loops using Recursion

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


It is 0 in the first iteration.

for(<this gets done before the first iteration>; <this gets checked before each iteration>; <this is done at the end of each iteration>) {
  // loop body

That’s great, thanks for the help!

I’m glad I could help. Happy coding!