In this video,
you will make the sprite respond to
the user's input.
In the last video, you added an ask block.
The ask block works with the answer block.
When you use an ask block, Scratch saves
the user's response in the answer block.
Find the answer block in the sensing menu.
Explore how the answer block works
by clicking the check box next to it.
The answer value will show up
in the top left corner of the stage.
Click on the ask block and enter a response.
You should see the text you entered
appear in the top left corner of the stage.
Each time you click the ask block
and enter a response, the answer box
will update with the new value.
Now program the sprite to check if the answer
the user answered is the correct one.
Say something like, you win, if the user is correct.
To check if something is true,
use a conditional block.
Computers use conditional statements to make decisions.
Drag out an if else block from the control menu
and snap it below the ask block.
Notice the diamond shaped space in the if else block.
This space is for a block called a boolean.
A boolean is a statement that is
either true or false.
For this project, the boolean will determine
whether the answer your friend entered
equals the correct answer.
In the operators menu, find the block
that has an equals sign.
Then, from the sensing menu,
drag out the answer block
and place it inside the first value of the equals block.
Type the letter that matches the lie
into the second half of the operator block.
In this example, the lie is the c statement
but you will type in the letter for the statement
that is a lie in your project.
To test whether this works correctly,
click on the ask block, type in the letter
for your lie statement when you are prompted,
then, click the green operator block.
It says true.
That's because the answer block saved the value
you just typed when running the code.
The operator block compared answer to the letter c.
Since they are equal, it says true.
If you enter a different value, like b,
then it will say false.
Drag the green operator block into the if else block.
Now, you can read the code like a sentence.
If the answer equals c, or the lie, then a
winning action should happen.
To program the winning condition,
click on the looks menu and drag a save lock
into the if section of the conditional block.
Change the text to something that indicates
you picked the lie, like, you win.
Try it out.
First, the sprite says one true thing
then it says the second true thing,
then the sprite says the lie.
Next it asks the user a question.
In this example, the user enters c.
The program checks to see if the answer matches the lie,
it does, so the sprite says, you win.
Test your code a few times to make sure it works.
Try entering different values like a, b, or c.
Now it's your turn.
Check if the user's answer is the lie
using an if else block
and an equals operator block.
Program a winning condition by placing
a save block in the if else block.
Sign in to save your project and track your progress.