I don't understand this function proposal

Tell us what’s happening:
" multiply the elements from 0 to n inclusive in an array to create the product of those elements"
e.g. 0 to 9 would be 0x1 , 0x2 , 0x3, 0x4 … or would be 0x1, 1x2, 2x3, 3x4 , 3x5, 3x6, 3x7, 3x8, 3x9 ?
could someone give me a e.g. of “sum( )” and “multiply( )”?

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

Your code so far

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; rv:71.0) Gecko/20100101 Firefox/71.0.

Challenge: Replace Loops using Recursion

Link to the challenge:

it is from index 0 to index n, not from number 0 to number n

and the result would be the multiplication of all numbers at indexes from 0 to n

for example, if n is 3 the function would do arr[0] * arr[1] * arr[2] * arr[3]


The goal of this challenge:
" Write a recursive function, sum(arr, n) , that returns the sum of the elements from 0 to n inclusive in an array arr ."

with expected result (from challenge): "sum([2, 3, 4], 1) should equal 5."

^^ what @ilenia said arr[0] + arr[1] = 5

1 Like