Combine Arrays with the Spread Operator

Tell us what’s happening:
I don’t know what’s wrong.

Your code so far


function spreadOut() {
  let fragment = ['to', 'code'];
  let sentence =  ['learning', 'to', 'code', 'is', 'fun']; // change this line
  return sentence;
}

// do not change code below this line
console.log(spreadOut());

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/combine-arrays-with-the-spread-operator/

In your sentence array, you need to use the spread operator to add content of fragment array. You can’t just hardcode ‘to’ and ‘code’…

I should write that code:
function spreadOut() {
let fragment = [‘to’, ‘code’];
let sentence; // change this line
return sentence = [‘learning’, ‘to’, ‘code’, ‘is’, ‘fun’];
}

// do not change code below this line
console.log(spreadOut());

Your reply is for first code right?My s econd code is right?

Can you write me a example of spread operator.

Yes but I can’t understand the example.

How can I make my code same of example?

That don’t tell me nothing for how can I do the speadOut operator.

Can I ask you something?>

Yes…when write that code:
function spreadOut() {
let fragment = [‘to’, ‘code’];
let sentence; // change this line
return sentence = [“learning”, “to”, “code”, “is”, “fun”];
}

// do not change code below this line
console.log(spreadOut());

It tell me that spreadOut should return ["learning", "to", "code", "is", "fun"] is right.But you tell me it isn’t right.

And what can I write in this code?

I don’t want the answers but I am tell you that I don’t understand and we are in forum iof free code camp and you should to help me if I don’t understand but thank you for helping I will see again my exercise and I tell you.

Ok thank you for help.

Hi, @Klaudia. The whole idea of this challenge is not just only to pass it, but also to make you understand new concepts and give you more knowledge. @camperextraordinaire is doing a great job by pushing you to learn and look through the instructions attentively. Take a look at the example given in the instructions. Can you see the spread operator ... on line 2 and how it is used to place already declared array into another and merge them together? Do you understand what is happening? If so, there should be no problem for you to complete this exercise, because it’s basically the same stuff.
Try to absorb new concepts and use them. They were created to help and let you write your code faster and cleaner. Hope this helps :slightly_smiling_face: Happy coding!

1 Like

Thank you you help me very much>

@Klaudia
You need to use spread operator(…) which you learned in earlier ES6 , Below code will work and pass your test cases
let sentence = ['learning', ...fragment, 'is', 'fun'];