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 What's the Password?

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.

Choose an Add-On
Walking
In this video, you’ll learn how to make it look like the character is walking towards or away from the door.
What's the Password?
In this add-on, you'll program a secret password that the user must enter to travel through the secret door.
Make it Rain
In this add-on, you'll learn how to use the backpack to add the rain from your day 3 project into this project.
Find the Secret Door
In this add-on, you'll program the main character so the audience can use the arrow keys to find the secret door.
Add Another Character
In this add-on, you'll add more characters to your story.
Add Another Scene
In this add-on, you'll be prompted to add another scene, and given some ideas about how to program it.
arrow_backward Back
Next arrow_forward
Instructions
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!