You can program your chatbot to decide what to do based on the answers it receives.
First, you’re going to make your chatbot ask a question that can be answered with “yes” or “no”.
Change your chatbot’s code. Your chatbot should ask the question “Are you OK name”, using the
variable. Then it should reply “That’s great to hear!” name
if
the answer it receives is “yes”, but say nothing if the answer is “no”.
To test your new code properly, you should test it twice: once with the answer “yes”, and once with the answer “no”.
At the moment, your chatbot doesn’t say anything to the answer “no”.
Change your chatbot’s code so that it replies “Oh no!” if it receives “no” as the answer to “Are you OK name”.
Replace the if, then
block with an if, then, else
block, and include code so the chatbot can say "Oh no!"
.
Test your code. You should get a different response when you answer “no” and when you answer “yes”: your chatbot should reply with “That’s great to hear!” when you answer “yes” (which is not case-sensitive), and reply with “Oh no!” when you answer anything else.
You can put any code inside an
block, not just code to make your chatbot speak!if, then, else
If you click your chatbot’s Costumes tab, you’ll see that there is more than one costume.
Change your chatbot’s code so that the chatbot switches costumes when you type in your answer.
Change the code inside the
block to if, then, else
switch costume
.
Test and save your code. You should see your chatbot’s face change depending on your answer.
Have you noticed that, after your chatbot’s costume has changed, it stays like that and doesn’t change back to what it was at the beginning?
You can try this out: run your code and answer “no” so that your chatbot’s face changes to an unhappy look. Then run your code again and notice that your chatbot does not change back to looking happy before it asks your name.
To fix this problem, add to the chatbot’s code to
at the start switch costume
when the sprite is clicked
.