How does javascript interpret this?

product *= arr[i]

If I was a computer what would I do?

  **Your browser information:**

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

Challenge: Counting Cards

Link to the challenge:

Take the current value of product, get the value saved in arr[i], multiply, write into product.

It is just a shorthand for:

product = product * arr[i];

const arr = [2, 5];
let product = 10;

product *= arr[0];
console.log(product); // 20

product = product * arr[1];
console.log(product); // 100
1 Like

When in doubt, look it up in the docs.

Thank you so much.
I appreciate

Thanks man.

I’m just confused how arr[i] works

Isn’t i a different variable from arr?

or does arr[i] mean that since i = 0, i should be used as an index for arr?

Yes, arr is an array of elements. i is an index. If i is 0, then arr[i] is the first element in the array, like arr[0].

1 Like

Thank you Kelvin.
I’ve been observing your support to people.

Thanks man.

1 Like