Time for action - add it to the list

Because we want to avoid duplicates, we're going to check to see if the value in the answer block exists in the questions list.

  1. Add the if block to the when seeker clicked script.
  2. From the Operators palette, add the not block as the condition to check in the if block.
  3. From the Variables palette, add the contains block to the not block. Select the questions list from the drop down.
  4. Next, add the answers block from the Sensing palette to the contains block.

    Tip

    The answer block is a reporter, which means you can display its value on the stage by selecting it from the Sensing palette. You can also see its value by single clicking on the answer block.

  5. If the questions list doesn't contain the answer, add it to the list. From the Variables palette, add the add to block to the if block. Select questions from the drop down.
  6. Add the answers block to the add to block. Your script should look like the following screen shot.
Time for action - add it to the list

Test your script by typing answers that exist in the questions list and by typing answers that don't exist in the list. You can monitor the values in the questions list by turning on the questions reporter block in the Variables palette.

What just happened?

The not operator made our conditional statement read, "If the answer is not contained in the list, then add it to the questions list." By comparing the value in the answer block to any value in the questions block, we were able to determine whether or not we should add the answer to the list.

Join two text phrases

Not only did Scratch 1.4 give us the ability to capture keyboard input for use in our scripts, it allows us to perform additional operations, such as joining two text phrases together.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.198.233