Basic Data Structures - Combine Arrays with the Spread Operator

Tell us what’s happening:
Following in my code but I am getting undefined, why? the way I understand it, the function body has a variable name fragment which has an array, next there is another variable name sentence which is equal to the mix of an array and spread, and on the third line, I m returning that element.

Outside of the function I am console.log the function, but why is it undefined, I do have a return in the function body

  **Your code so far**
function spreadOut() {
let fragment = ['to', 'code'];
let sentence; ['learning',...fragment,'is','fun']// Change this line
return sentence;
}

console.log(spreadOut());
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Basic Data Structures - Combine Arrays with the Spread Operator

Link to the challenge:

let sentence; ['learning',...fragment,'is','fun']// Change this line

Replace the ; by and = sign, that is how a variable is assigned a value.

Or also, but it is less efficient:

//...(inside function)
let sentence;
sentence = ['learning',...fragment,'is','fun']
1 Like

oh wow. Thank you. I read it twice and didn’t notice

1 Like

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