# Create a Guess The Number Game | Challenge!

Use random number generators to make a number guessing game.

Featured Formulas

Video Transcript

Hello, welcome. This video is Ave a very fun sort of game that we're gonna make and I actually have a challenge for you before we start. So I'm gonna show you what it does. You then can pause the video and go and try to create it yourself and then come back. I'll give you some time to pause and then come.

And see if the way that we do it is the same. Cuz I'm sure there are other ways to do this. There's many ways to sort of do the same thing in Google Sheet sometimes. So I don't think that my way is exactly the, the, the, the right way or there's the only way. But we've created a guessing game here, and what you do is in the blue, you guess a number, either zero up to 10.

So there's 11 numbers generally. And the one in B five is going to change. Again, I'm not gonna show you how it works until after the spoiler break, so I'm gonna break one. I'll show it to you. I'll do, I'll run it and then you try to create it if you want. Okay. So first here, so you just enter a number here.

We can actually click this button. Guess a number. And this is changing. Each time I can even type in number. And once we get the correct one, it turns green and it says you win here, we won. Now from just that, you can pause the video right now and try to replicate this as best you can. And if you do get it to work make sure you.

that you got it. That you made it before you watched the video, the rest of the video. And if you didn't get it, if you went away, tried it, couldn't figure it out.  and then, then come back and watch the rest of the video and I'll show you at least one way to do it. But if, but comment, either actually comment either way.

Did you make it or did you not? And so this is the end of the spoiler break. From this moment on, I will tell you how this works. You have had plenty of time to pause the video and go and try to make it. I didn't, I tried to give you no more information than you saw here. And so now I will reveal how this works.

Is let, let's actually just, just in case, let's type in the number a little bit more and see every time we type in a number, the B five changes. And we can try zero and we'll just do it one more time. Try to get a winner. There we go. And here it is. What we use is Rand Rand times 10, and I round that number.

Okay. So what Rand is doing is it's a random number generator. See, this one says 0.49155 and round is rounding it to the nearest index in integer. But it's actually multiplying by 10. So it's actually, this is for, oh, there you go. Nine. This is changing every time we edit. And so what happens is brand The function changes literally every time we edit the sheet.

So we, we don't even edit this. I'm not, we could actually edit anything and it's going to change that number here. Then right here I have an if equation or function and I say, oh, wait, if we had guessed 11 or 12, it says, guess 10 or lower. So we tried 10 and that says, keep guessing because.  C five here is over 10.

It says guess 10 or lower. If it's not, it then says if these two are the same, it says you win. And if not, if it's false, if both of those are false, if it's a number under 10 and 10 or lower, and these are not equal, it'll say keep guessing. So so how do I then, so the last thing is how do you get the green?

Okay, this is actually the fun part. Let's look at conditional formatting format, conditional formatting. And what we use here is a custom formula that literally says this equals B five equals C five. So we're saying this conditional formatting when B five equals C five then do this color. And we're just saying the color is gonna be on B five.

So, B.  if B five equals C five. And, and it's a weird thing and let me try to explain this. If you've never seen this kind of custom formula before, is we can set the custom formula to anything you want. The this to the right has to be a formula that has an equal sign or some operator. This first equals sign is not actually equals, it's more like the word is so, or, or the word equal.

Yeah. It's more like the word is, it's like the custom formula is, well, is B five equals C five? The first equal sign doesn't matter or doesn't does matter. If we don't have it it's not gonna work. But the having the equal sign is saying that this custom formula is equal to this whole thing. So that's why we have A equals B five equals.

I know this looks totally strange and it is totally strange cuz these two equal sign meaning actually slightly different things. So this is how we that I did it. And now we can keep guessing and you know. Exactly. And it actually is a game. It is a guessing game. It's not set up. There's no secret numbers hidden somewhere.

This is truly gonna give a random number each time. And if they equal, we. If you, there we go. We won. Okay. So if you want to try anything harder, something that I was thinking about doing and, and, and couldn't necessarily figure out ex unless I was doing scripting. If you have, actually this is probably a good exercise.

If you have done scripting, you walk through the scripting  videos that I've made and you've done some scripting on your own, then you probably could do like number of tries here. And essentially you would say, like, set up a formula that, that for every edit that happens. So maybe using the on edit script, you add one to D five, and so you maybe say number of tries, number of tries here and that.

anytime you edit. So every time you do that, which is an on edit, you add a number here, you plus one. And that's pretty simple. Once you do the where is it? Tools, script editor, and if you know some editing scripting, you might be able to do that. So I'm actually gonna leave that open. If you had again, comment if you tried to make the game yourself before getting to the spoiler break, comment below if you did.

Accomplish that and you won. And not just winning the number guessing game, but you actually won by creating this yourself. Comment below, you won. Great. Two thumbs up, then try adding the number of tries. I'm not actually gonna do that right now. But if anybody tries and well accomplishes it or even tries and doesn't get it I'm more than happy to give it a go and try myself.

I think it, it'll be having, having to do something with the unedited script and then adding.  Getting the value of D five and adding one. The only issue I have right now is I would not, I don't know how I would handle sort of, once you've won, resetting this D five to zero, that's the big question that I don't even know.

I would have to figure that out on the fly as well. So if you try it and you, you've attempted to do a, a number of tries here, let me know your solution and we can show it off. I have.  Facebook group called I Love Google Sheets. Go to facebook.com/groups/i love Google Sheets. Join that show off your try show off your sheets, and if you've done that script, then, then show it off there that you, you accomplish this.

Game and you've won the meta game. Thanks for watching. Hopefully you enjoyed seeing how to make a guessing game, try some other games. I've also created an Easter egg hunt in a Google sheet. I actually am making this video in the middle of trying to make a hangman video on how to make that in Google sheet.

So if, if you see that, go check that out, go check the hangman, if I've accomplished that, that video is available for you to watch. Bye.

Better Sheets