Help me I hate this, this isn't alright

Tell us what’s happening:
I put everything I can think of with the instruction and can’t figure this out :frowning:

 **Your code so far**
function checkSet(set){
// Only change code below this line
const checkSet = new Set([1,2,3,4,5,6,7])
var setToArr = [...1,2,3,4,5,6,7]
console.log(1,2,3,4,5,6,7)
// Only change code above this line
}
 **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15

Challenge: Use Spread and Notes for ES5 Set() Integration

Link to the challenge:

HI @khoi.khong20 !

I would reset the lesson.

There are two fundamental things missing from your code.

No.1:
You are not using the function parameter called set

No.2:
You are not returning anything in your function.

Your answer should only be one line and should incorporate those two things.

Take a close look at function call here

checkSet(new Set([1,2,3,4,5,6,7])

It is already using the set object.

You don’t need to do that again here

The challenge wants you to use the spread operator and return an array containing the values of the Set.

Hope that helps!

1 Like

Thank you, I just redid the code and I only have to return its containing value like this: “return ([1,2,3,4,5,6,7])” and challenge was complete. I struggled this in the morning and wasn’t sure I could beat this but thank you for the help. Much appreciated.

While this does pass the challenge, unfortunately it missing the learning component of the challenge.
Right now you are returning a hardcoded array of seven numbers to pass the challenge.

But what if I wanted to test this function using this function call

checkSet(new Set([17,2,8]))

Right now your code would return [ 1, 2, 3, 4, 5, 6, 7 ] which wouldn’t make sense in this context.

That is why you want to use the spread operator with the function parameter of set.

function checkSet(set){
   // Only change code below this line
return [...set]
   // Only change code above this line
}

Now our code will produce the correct results for the checkSet(new Set([17,2,8])) function call.

Remember that you want to write functions that use the function parameters and can be reusable for hundreds or even thousands of function calls. :slight_smile:

1 Like