Sorry if this is kind of a “dumb” question, but the wording is throwing me off.
“multiply the first n elements of an array to create the product of those elements”. I’m trying to translate that sentence another way, but can’t seem to know what “the first n” means. Your code so far
function sum(arr, n) {
// Only change code below this line
console.log(`the array is [${arr}]`);
console.log(`the number is ${n}`);
// 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/105.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Replace Loops using Recursion
In this case n is basically a placeholder for a possible number. So if i gave you the number 3 you would multiply the first 3 elements of an array, but it could be any number for n. So if you check the test they have function calls like sum([1], 0) or sum([2, 3, 4, 5], 3) where the number at the end represents the amount of numbers you should sum together from the arrays.
If I have 5 numbers [2, 3, 1, 3, 4], the product of the first 4 numbers is 18.
Using this formula instead, if I multiply the product of the first 3 numbers, 6, by the 4th number, 3, I get 18, which is the same thing as ‘the product of the first 4 numbers’.
To help understand this, start by thinking about the following task: multiply the first n elements of an array to create the product of those elements.
I didn’t know what multiply the first n elements meant. When I log N to the console I got 0 1 3. I know that sentence was in the instructions, I just did not understand.
The entire sentence matters. (In general with technical explanations the entire sentence matters and skipping parts of a sentence can change the meaning) Do you know what ‘the product of the elements’ means?
Not understanding the second formula. “Using this formula instead, if I multiply the product of the first 3 numbers, 6, by the 4th number, 3, I get 18, which is the same thing as ‘the product of the first 4 numbers’”. I’m sorry lol. Why would we even need to do that? I’m confused