Title Learn to Program with Scratch English 18.4 MB 291
```                            About the Author
Acknowledgments
Introduction
Whom This Book Is For
Features
Organization of This Text
Conventions Used
Online Resources
Chapter 1: Getting Started
What Is Scratch?
Scratch Programming Environment
Sprite List
The Stage
try it out 1-3
Blocks Tab
Scripts Area
try it out 1-5
Costumes Tab
try it out 1-7
Sprite Info
Backdrops Tab
Sounds Tab
Toolbar
Paint Editor
Setting the Center of an Image
try it out 1-10
Setting Transparent Color
Step 1: Prepare the Backdrop
Step 3: Start the Game and Get Your Sprites Moving
try it out 1-11
Step 4: Spice It Up with Sound
Scratch Blocks: An Overview
Arithmetic Operators and Functions
Arithmetic Operators
Random Numbers
Mathematical Functions
Summary
Problems
Chapter 2: Motion and Drawing
Using Motion Commands
Absolute Motion
Relative Motion
try it out 2-2
Other Motion Commands
Pen Commands and Easy Draw
try it out 2-3
try it out 2-4
The Power of Repeat
try it out 2-5
Rotated Squares
Exploring with Stamp
try it out 2-7
Scratch Projects
Get the Money
Catching Apples
More on Cloned Sprites
Summary
Problems
Chapter 3: Looks and Sound
The Looks Palette
Changing Costumes to Animate
try it out 3-1
Image Effects
Sprites That Speak and Think
try it out 3-3
Layers
The Sound Palette
Playing Audio Files
Controlling Sound Volume
Composing Music
Playing Drums and Other Sounds
try it out 3-5
Setting the Tempo
Scratch Projects
Dancing on Stage
Fireworks
Summary
Problems
Size and Visibility
Chapter 4: Procedures
Message Broadcasting to Coordinate Multiple Sprites
Creating Large Programs in Small Steps
Passing Parameters to Custom Blocks
try it out 4-1
Using Nested Procedures
try it out 4-2
Working with Procedures
Breaking Programs Down into Procedures
try it out 4-3
Building Up with Procedures
Summary
Problems
Chapter 5: Variables
Data Types in Scratch
What’s in the Shape?
Automatic Data Type Conversion
Introduction to Variables
What Is a Variable?
Creating and Using Variables
Try It Out 5-1
The Scope of Variables
Changing Variables
Try It Out 5-2
Variables in Clones
Displaying Variable Monitors
Using Variable Monitors in Applications
Simulating Ohm’s Law
Try It Out 5-3
Demonstrating a Series Circuit
Visualizing a Sphere’s Volume and Surface Area
Try It Out 5-5
Drawing an n-Leaved Rose
Try It Out 5-6
Modeling Sunflower Seed Distribution
Getting Input from Users
Performing Arithmetic Operations
Summary
Problems
Chapter 6: Making Decisions
Comparison Operators
Evaluating Boolean Expressions
Comparing Letters and Strings
Decision Structures
The if Block
Using Variables as Flags
The if/else Block
Nested if and if/else Blocks
Logical Operators
The and Operator
The or Operator
The not Operator
Using Logical Operators to Check Numeric Ranges
Scratch Projects
Guess My Coordinates
try it out 6-1
Triangle Classification Game
try it out 6-2
Line Follower
Equation of a Line
Other Applications
Summary
Problems
Chapter 7: Repetition: A Deeper Exploration of Loops
More Loop Blocks in Scratch
The repeat until Block
try it out 7-1
Building a forever if Block
try it out 7-2
Stop Commands
try it out 7-3
Ending a Computational Loop
Validating User Input
Counters
Counting by a Constant Amount
Revisiting Nested Loops
Recursion: Procedures That Call Themselves
Scratch Projects
Analog Clock
Bird Shooter Game
try it out 7-8
Free-Fall Simulation
try it out 7-9
Projectile Motion Simulator
try it out 7-10
Other Applications
Summary
Problems
Chapter 8: String Processing
Revisiting the String Data Type
Counting Special Characters in a String
Comparing String Characters
try it out 8-1
String Manipulation Examples
Igpay Atinlay
try it out 8-2
Fix My Spelling
try it out 8-3
Unscramble
Scratch Projects
Shoot
try it out 8-4
Binary to Decimal Converter
try it out 8-5
Hangman
try it out 8-7
Fraction Tutor
try it out 8-8
Summary
Problems
Chapter 9: Lists
Lists in Scratch
Creating Lists
try it out 9-1
List Commands
try it out 9-2
Bounds Checking
Dynamic Lists
Filling Lists with User Input
Creating a Bar Chart
try it out 9-3
Numerical Lists
Finding Min and Max
Finding the Average
try it out 9-5
Searching and Sorting Lists
Linear Search
Frequency of Occurrence
try it out 9-6
Bubble Sort
Finding the Median
Scratch Projects
The Poet
try it out 9-8
try it out 9-9
Math Wizard
Flower Anatomy Quiz
Other Applications
Summary
Problems
Appendix: Sharing and
Collaboration
Creating a Scratch Account
Using the Backpack
Starting a New Project
Remixing a Project
The Project Page
Index
```
##### Document Text Contents
Page 1

Layer 5

L E A R N T O
P R O G R A M W I T H

S C R A T C H

L E A R N T O
P R O G R A M W I T H

S C R A T C H
A V I S U A L I N T R O D U C T I O N T O P R O G R A M M I N G

W I T H G A M E S , A R T , S C I E N C E , A N D M A T H

M A J E D M A R J I

C
O

V E R
S

S
C

R
A T C

H
2

SH
ELV

E IN
:

CO
M

PU
TERS/

PRO
G

R
A

M
M

IN
G

LAN
G

U
AG

ES

\$34.95 (\$36.95 CDN)

www.nostarch.com

TH E F I N EST I N G E E K E NTE RTA I N M E NT ™

Scratch is a fun, free, beginner-friendly programming
environment where you connect blocks of code to build
programs. While most famously used to introduce kids
to programming, Scratch can make computer science

countless lines of code in a cryptic programming lan-

script, and with a single click, you can even test any
coded blocks plainly show each logical step in a given

how to:

approachable for people of any age. Rather than type

M
A

R
JI

L
E

A
R

N
T

O
P

R
O

G
R

A
M

W
IT

H
S

C
R

A
T

C
H

L
E

A
R

N
T

O
P

R
O

G
R

A
M

W
IT

H
S

C
R

A
T

C
H

guage, why not use colorful command blocks and
cartoon sprites to create powerful scripts?

• Harness the power of repeat loops and recursion

• Use if/else statements and logical operators to make
decisions

program
• Store data in variables and lists to use later in your

• Read, store, and manipulate user input

Hands-on projects will challenge you to create an

• Implement key computer science algorithms like linear
searches and bubble sorts

Ohm’s law simulator, draw intricate patterns, program
sprites to mimic line-following robots, create arcade-style
games, and more! Each chapter is packed with detailed
explanations, annotated illustrations, guided examples,
lots of color, and plenty of exercises to help the lessons

Wayne State University in Michigan. He holds a PhD

A B O U T T H E A U T H O R

Majed Marji is a senior development engineer at
General Motors and an adjunct faculty member at

in electrical engineering from Wayne State University
and an MBA in strategic management from Davenport
University.

stick. Learn to Program with Scratch is the perfect place
to start your computer science journey.

G U I D E T O
( A N D P A I N L E S S )
A N I L L U S T R A T E D

C O M P U T E R
S C I E N C E

G U I D E T O
( A N D P A I N L E S S )
A N I L L U S T R A T E D

C O M P U T E R
S C I E N C E

In Learn to Program with Scratch, author Majed Marji
uses Scratch to explain the concepts essential to solving
real-world programming problems. The labeled, color-

www.it-ebooks.info

http://www.it-ebooks.info/

Page 146

124 Chapter 6

In many programming situations, however, you may want to alter this
sequential flow of program execution. If you were writing an application to
tutor children in basic arithmetic, you’d want to execute certain blocks to
reward correct answers and a completely different set of blocks for wrong
answers (to reveal the right answer or offer another chance, for example).
Your script can decide what to do next by comparing the student’s input
with the correct answer. This is the basis of all decision-making tasks.

In this chapter, we’ll explore the decision-making commands available
in Scratch and write several programs that use these commands to test
inputs and perform different actions.

First, I’ll introduce you to Scratch’s comparison operators and show
how you can use them to compare numbers, letters, and strings. Then, I’ll
introduce the if and if/else blocks and explain their key role in decision
making. You’ll also learn how to test multiple conditions using nested if and
if/else blocks and write a menu-driven program to put these blocks into
action. After that, I’ll introduce logical operators as an alternative way to
test multiple conditions. In the last section, we’ll write several interesting
programs based on all of the concepts you’ve learned so far.

comparison operators
You make decisions every day, and each decision normally leads you to per-
form certain actions. You may think, for example, “If that car is less than
or not you want to buy it.

You can make decisions in Scratch, too. Using comparison operators,
you can compare the values of two variables or expressions to determine
whether one is greater than, less than, or equal to the other. Comparison
operators are also called relational operators because they test the relation-
ship between two values. The three relational operators supported in
Scratch are shown in Table 6-1.

Table 6-1: Relational Operators in Scratch

Operator Meaning Example

greater than

Is price greater than 2,000?

less than

Is price less than 2,000?

equal to

Is price equal to 2,000?

www.it-ebooks.info

http://www.it-ebooks.info/

Page 291

Layer 5

L E A R N T O
P R O G R A M W I T H

S C R A T C H

L E A R N T O
P R O G R A M W I T H

S C R A T C H
A V I S U A L I N T R O D U C T I O N T O P R O G R A M M I N G

W I T H G A M E S , A R T , S C I E N C E , A N D M A T H

M A J E D M A R J I

C
O

V E R
S

S
C

R
A T C

H
2

SH
ELV

E IN
:

CO
M

PU
TERS/

PRO
G

R
A

M
M

IN
G

LAN
G

U
AG

ES

\$34.95 (\$36.95 CDN)

www.nostarch.com

TH E F I N EST I N G E E K E NTE RTA I N M E NT ™

Scratch is a fun, free, beginner-friendly programming
environment where you connect blocks of code to build
programs. While most famously used to introduce kids
to programming, Scratch can make computer science

countless lines of code in a cryptic programming lan-

script, and with a single click, you can even test any
coded blocks plainly show each logical step in a given

how to:

approachable for people of any age. Rather than type

M
A

R
JI

L
E

A
R

N
T

O
P

R
O

G
R

A
M

W
IT

H
S

C
R

A
T

C
H

L
E

A
R

N
T

O
P

R
O

G
R

A
M

W
IT

H
S

C
R

A
T

C
H

guage, why not use colorful command blocks and
cartoon sprites to create powerful scripts?

• Harness the power of repeat loops and recursion

• Use if/else statements and logical operators to make
decisions

program
• Store data in variables and lists to use later in your

• Read, store, and manipulate user input

Hands-on projects will challenge you to create an

• Implement key computer science algorithms like linear
searches and bubble sorts

Ohm’s law simulator, draw intricate patterns, program
sprites to mimic line-following robots, create arcade-style
games, and more! Each chapter is packed with detailed
explanations, annotated illustrations, guided examples,
lots of color, and plenty of exercises to help the lessons

Wayne State University in Michigan. He holds a PhD

A B O U T T H E A U T H O R

Majed Marji is a senior development engineer at
General Motors and an adjunct faculty member at

in electrical engineering from Wayne State University
and an MBA in strategic management from Davenport
University.

stick. Learn to Program with Scratch is the perfect place
to start your computer science journey.

G U I D E T O
( A N D P A I N L E S S )
A N I L L U S T R A T E D

C O M P U T E R
S C I E N C E

G U I D E T O
( A N D P A I N L E S S )
A N I L L U S T R A T E D

C O M P U T E R
S C I E N C E

In Learn to Program with Scratch, author Majed Marji
uses Scratch to explain the concepts essential to solving
real-world programming problems. The labeled, color-

www.it-ebooks.info

http://www.it-ebooks.info/