Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Quel est le mot de passe ?

Transcript

This add-on uses a new concept, “repeat until,” and is more challenging than some of the others.

As the programmer, you will get to choose the password. First, you will need to ask for the password.

To do this, use the same block you used to ask if the character should go through the secret door, the “ask” block. Type a question in the “ask” block. This example says, “Apparently to go through the door I need a password. What is the password?”

This add-on is different from “should I go through the secret door?” in the core project. In this add-on, if the user doesn’t get the password right, the program will keep asking for a password. To keep doing something over and over, use a loop. The “repeat until” loop, for example, allows something to keep happening until a condition is met. From the control menu, drag out a “repeat until” loop. Place it below the “ask” block. Start by filling out the condition.

In the core project, the condition was “answer = yes.” The condition for this add-on is very similar: This example uses the password “scratch,” so the condition reads “answer = scratch.”

For this add-on, the program should keep asking for a password until the user enters the correct one. To ask for the password again, put the “ask” block inside the “repeat until” loop. Make the “ask” block say something that will help the user understand what happened. This example says “That wasn’t right.

What else could it be?”

If not, they'll will be stuck inside the loop forever! Make sure you give the user a chance to enter the correct password. Click on this code to test it. The character asks for the password. To make sure the “repeat until” loop works, first type an incorrect answer. This example enters “cat.”

Since the condition “answer = scratch” was not met, the code inside the repeat loop will execute. For this example, that code asks “That was not correct, what else could be?” Try one more incorrect test. This example types “dog.” The code inside the repeat loop should run again.

This time, answer correctly. In this example, the correct password "scratch" is entered.

So the repeat loop stops running and the story continues.

If you would like your story to wait to start until the correct password is entered, place the code you just created under the green flag. You could also instruct the program to ask for the password before the character goes through the secret door, or at another point in the story that makes sense to you. This example asks for the password when the user has already decided to go through the door, so it runs after the “then” portion of the “if answer = yes” block. Test your code by clicking on the green flag.

The program should only continue after you’ve entered the right password.

Finally, you can add a “say” block that lets the user know the password was correct.

Choisir une extension
Marcher
Dans cette vidéo, tu vas découvrir comment créer l'effet que le personnage marche en direction de la porte ou s'en éloigne.
Quel est le mot de passe ?
Dans cette extension, tu vas programmer un mot de passe secret que l'utilisateur devra taper pour pouvoir franchir la porte secrète.
Faire tomber la pluie
Dans cette extension, tu vas apprendre à utiliser le sac à dos pour ajouter la pluie de ton projet de l'activité 3 dans ce projet.
Trouver la porte secrète (défi)
Dans cette extension, tu vas programmer le personnage principal pour que le public puisse utiliser les touches fléchées pour trouver la porte secrète.
Ajouter un autre lutin
Dans cette extension, tu vas ajouter d'autres personnages à ton histoire.
Ajouter une autre scène (défi)
Dans cette extension, tu vas être invité à ajouter une autre scène et tu recevras des idées sur la façon de la programmer.
arrow_backward Retour
Suivant arrow_forward
Instructions
  1. Choisis une extension, et clique sur "Regarder" pour découvrir comment la créer.
  2. Une fois que tu as terminé une extension, essayes-en une autre !