SCRATCH GOLD II
SCRATCH GOLD I
2 of 3

4.05 Making decisions

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 name variable. Then it should reply “That’s great to hear!” if the answer it receives is “yes”, but say nothing if the answer is “no”.

Testing a chatbot reply
Testing a chatbot reply
nano sprite

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!".

nano sprite

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.

Testing a chatbot reply
Testing a yes/no reply

You can put any code inside an if, then, else block, not just code to make your chatbot speak!

If you click your chatbot’s Costumes tab, you’ll see that there is more than one costume.

chatbot costumes

Change your chatbot’s code so that the chatbot switches costumes when you type in your answer.

Testing a changing costume
Testing a changing costume

Change the code inside the if, then, else block to switch costume.

nano sprite

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.

Costume bug

To fix this problem, add to the chatbot’s code to switch costume at the start when the sprite is clicked .

nano sprite
Testing a costume fix
×
×

Cart