课程: JavaScript: Maps and Sets

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Sets 2

Solution: Sets 2

(upbeat music) - [Instructor] For this challenge, we're given an array of guesses. We're also given a winning number, and we need to determine, is that winning number in our guesses set that we're going to create? So the first thing that we want to do is set up our set. So very similar to the challenge that you just completed. We're going to go ahead and create a new variable, and I'll call that guessesSet, and we'll instantiate a new set here. Then, very similar to last time, I'm going to loop over this guesses array, and for each value, I'm going to add it to our set. As I mentioned before, there could be a number of different ways that you decide to do this. I'm going to show you one way that's going to give you some practice with array methods as well. If you choose to do it another way, that's totally fine, as long as you get the correct answer or solution and using a set, then you've done what you're supposed to do. So let's go ahead and we'll reference our array of guesses, and…

内容