CS 139 Algorithm Development
Lab02A: I/O, variables, and operators

Background

This final Scratch lab will introduce more advanced programming constructs that allow you to manipulate numbers and text. We will also explore several ideas and techniques for your self-directed programming assignment due later this week.

Objectives

The students will:

Key Terms

I/O : input/output, or the communication between a program and its user
Variable : a symbolic name associated with a value or storage location
Operator : a symbol that represents a common arithmetic or logic function

Materials Needed

Instructions

Write the answers to the numbered questions in a separate file. You may be asked to share your answers with the rest of the class. Submit your Scratch project and your answer file electronically via Blackboard.

References

This lab is adapted from the Scratch Curriculum Guide v20110923, released under the Creative Commons Attribution-ShareAlike license.

 


Part 1: Basic Conversion

As we transition to Java later this week, several of the example programs we will do involve converting values of one format into another. The purpose of this exercise is to write a small "conversion" program in Scratch.

Step 1. Begin with an empty Scratch project and click on the "Sensing" palette. Drag an "ask" block onto the scripts area. Click on the script and answer the question that the cat asks you.

Step 2. Now click the "Looks" palette and snap a "say" block under the "ask" block.

Step 3. Find the "join" block on the "Operators" palette.

Tip: Have you discovered the "Help > Help Page..." menu? You may want to refer to the Help Screens and Reference Guide linked from that page.

 

Step 4. Variables allow you to save values for use in blocks with rounded or rectangular holes (which correspond to numbers and text, respectively).

Step 5. Write a script that asks the user for a number of inches, converts that value into centimeters (1 in = 2.54 cm), and displays the result.

 


Part 2: Squares & Circles

Step 6. You have been hired to design a new marketing campaign for JMU sports. The coaches would like something with gold squares and purple circles. Refer to the "Shapes" handout for ideas. And try to incorporate the Duke Dog into your project somehow.

 


Part 3: Automatic Drawing

Step 7. In Scratch, each sprite has a "pen" it can draw with as it moves around the stage (see the "Pen" palette). This idea is known as turtle graphics and enables you to program your own drawings. For a completely random example, see the "Drawing" handout. Figure out how to draw something simple, like a geometric shape or repeating pattern.

Tip: Again, you should check out the Help Screens -- particularly the one about pen blocks.