Debugging - Catch Unclosed Parentheses, Brackets, Braces and Quotes

Tell us what’s happening:
Hi,
would someone please explain to me what I am doing wrong here?

Thank you.

Your code so far

let myArray = [1, 2, 3];
let arraySum = myArray.reduce((previous, current =  previous + current));
console.log('Sum of array values is: {arraySum}');

Your browser information:

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

Challenge: Debugging - Catch Unclosed Parentheses, Brackets, Braces and Quotes

Link to the challenge:

You have to write the reduce as a function call. What you’re looking for is:

let arraySum = myArray.reduce((previous, current) =>  previous + current);

Notice that the two parameters previous and current are enclosed in parenthesis because they are parameters of the function. Since you’re going to use this as an arrow function, you put => to indicate there is going to be a command following and then it is implied to return previous + current.

You could rewrite that function with the function keyword, too:

let arraySum = myArray.reduce(function (previous, current) {  return previous + current; })

The arrow function makes it a little more succinct.

Hi

Thank you for your beautiful explanation. However, as beautifully presented as it is, there is still a little confusion. First, to my understand, in human English, this whole thing is read thus: let arraySum = myArray.(.=multiply)reduce((previous, current) =>(I don’t know how to read/interpret this equal(=)behind arrow head (>) thing) previous + current);

Yeah, what does this equal sign behind arrow head (=>) mean??? How do I read it?

What’s in quotes (“”)? There is no quotation sign in the text, so you kind of confuse me a bit when you mentioned it. I only see parenthesis; what quotes are you talking about?

Then, let’s talk about the “arrow function.” Pray tell, what is an “arrow function?”

let arraySum = myArray.reduce((previous, current) =>  previous + current);

Thank you very much for your help in teaching me the rope of understanding this alien( :smiley:) language.

Ciao

Oops I did mean to say parenthesis, not quotes. But you should really retake the earlier courses. I think you’d benefit greatly from that. Arrow functions are covered in the ES6 section of the course.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.