請求各位大大,我不能過循環嵌套這一關,請幫助我,謝謝!

我打了code,如下:

function multiplyAll(arr) {

var product = 1;

// 只修改这一行下面的代码

for(var i= 0 ; i < arr.length; i++) {

for(var j = 0; j < arr[i].length; j++) {

product = product * arr[i][j];

}

}

// 只修改这一行上面的代码

return product;

}

multiplyAll([1],[2],[3])

console.log(product)

multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);

console.log(product)

multiplyAll9([[5,1],[0.2,4,0.5],[3,9]]);

console.log(product)

為何它的回應是product是没定義,但題目有給var product=1 而我又打code : product=product*arr[i][j]; 為何它的回應是product没定義???
請求各位大大協助,謝謝!

hwapipi

Can you include a link to the challenge?

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

Challenge: Nesting For Loops

Link to the challenge:

freecodecamp.org

freeCodeCamp.org

Learn to Code — For Free

You created a duplicate for this in English and I am answering you in that one instead. Please see your other post on this for my answer.

Also, try not to create duplicate issues.

Sorry I forget to post the Link.I had posted,thanks Mr.bb can help me.

Tell us what’s happening:
Describe your issue in detail here.
I type the codes below and its response is product is not defined but the step is given var product=1, I also type the code product*=arr[i][j]; why its response is product is not defined. I type below:

Your code so far

function multiplyAll(arr) {

var product = 1;

// 只修改这一行下面的代码

for(var i= 0 ; i < arr.length; i++) {

for(var j = 0; j < arr[i].length; j++) {

product *= arr[i][j];

}

}

// 只修改这一行上面的代码

return product;

}

multiplyAll([[1],[2],[3]])

console.log(product)

multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);

console.log(product)

multiplyAll9([[5,1],[0.2,4,0.5],[3,9]]);

console.log(product)

Your browser information:

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

Challenge: Nesting For Loops

Link to the challenge:

Your function code is actually correct. The problem you are having is that you added console.logs that are trying to print out a variable that doesn’t exist. You can’t access the variable product that is inside the function body like that. If you want to get the results of a function call then you have to use another variable to store the results. So your first function call should look something like:

let product = multiplyAll([[1],[2],[3]]);

Then you will be able to print the contents of product to the console. Or, you could just get rid of all the console.logs.

Oops, forgot to mention, you are calling the function by the wrong name in one of those:

multiplyAll9([[5,1],[0.2,4,0.5],[3,9]]);

Dear bb:
I use Chinese Forum and seems to no one partcipate no replies but English Forum has about 80 members participate so I trans to English Forum to post my question that is why I open two windows and unfortunately I close my English Forum’s window,so can’t to watch your answer.Could you tell me once again. Many thanks!

My answer has been merged into this thread. Just scroll up a little.

If you never get any response when using the Chinese forum then definitely just post in the English one. You can still post in Chinese though. We can all use google translate. Just don’t create duplicates. Choose one or the other.

Dear bb:
1.I scroll up but no finding the answer,it is very sorry ,sorry to you could you write again,many thanks thanks to you.
2.OK ,after time I all use English Forum to post my questions. Sorry !