Hello, in this video, I am going to show you the Generate function. So when a normal function is called the entire function is run with generate function, you call it and using certain keywords, you know, which we're going to show you from code yield, you essentially allow it to sort of, you know, pause on a particular moment. And then you can call the next little fantasy grape you want to know pass in a bunch of data, but you want the function maybe to alert the user of what they're putting into you don't directly put it in add parameter. Now let me just, you know, show you thought function. And I say, I'll say favorites. And the way you indicate a generate an Asterix here that tells the JavaScript interpreter that is a generator So in here, we're going to create a variable.
I'm going to call it pizza equals to yield. And now you put a quotation mark. And now what we are going to say, we are going to say is what is you? Then the ball will say, do game equals you. We'll do one more. copy this and I'll do it from the movie.
What is your favorite movie? And now we're gonna actually do, you're gonna return Yeah. And what we are actually going to return is going to be something T Dong cool and we ever return. So you want to put some so on my keyboard I seem to have lost it while going on a bunch of random characters here, but lo the random characters. Sorry I don't know why I thought that Okay, so I'm gonna return name and I'm going to dot and then I'm gonna say p not name dot game dot new return that. And the way we call it the creative variable, and we call it q for question equals favorites.
Like so. And then we're going to console dot log. I'm gonna say favorites or cue dot next. So this is basically going to get the next, you know, part in there the next yield, and we can get that out, we're going to do it. And the next one is where we actually pass in the parameters of pizza. I'm going to see game also offline.
And finally for maybe I'll say that Knowing if we said that let's see what we get. So we get some errors. First quality, what is your favorite pizza? Or your favorite game one movie 910 Okay, so this right here, he did this to Okay, we can console log on log like so with a pizza game. And you can see obviously we were rotation off and as an extra class what I want you to do is add some text in here just saying, you know my favorite pizza and it's my favorite game. Whilst I like watching this, as you can see, we do.
Okay, yeah. looks okay. Yep, everything's okay. And could we do this? We need the final line. So okay.
So this allows us to create a generate function. And this next keyword is goes through each individual yield. It's almost like asking the question in itself, but instead of doing it here and passing them all in our parameters, we can just, you know, group them all up this great way. If you have like a bunch of questions, you need to redo it again and again, you have the answers, you can just pass them in like so. last generation generator functions. If you have any questions, feel free to pop me a message, and I look forward to seeing you in the next video.