Beep boop. Are you on a mobile device?

codeCampus is a desktop / tablet experience. Log back in on one of those devices and we can get coding!

Get the bestselling book on coding!

Students: do this first!
  1. If you haven't already, read the...
    Chapter 1 - What is Code? storybook
    Chapter 2 - Intro to Scratch storybook.
    Chapter 4 - Forever Loops storybook.
  2. Open the Starter Project
  3. Login to your Scratch account*
  4. Click the blue "next" button above to go to the next step
  5. Get ready to code!
*Don't have a Scratch account?
Overview

  1. In this project we will create an application that lets us change the size of our fish as a fraction. We will use a loop to make our program run forever!

Step 1: Initialize (start) the Code

  1. Make sure you are coding the Fish sprite by clicking on the Fish sprite thumbnail.
  2. Click on the Events tab.
  3. Bring out a "when green flag clicked" block.

Step 2: Set the Fish's Starting Size

  1. The fish's size will change during the project.
  2. So, we want to make sure it always starts at its normal size.
  3. Click on the Looks tab.
  4. Bring out the "set size to 100%" block.
  5. Attach it to the bottom of the code.

Discussion

  1. The fish's starting - or normal - size is 100%.
  2. That is a whole number, so we can represent that with a fraction like 4/4, 5/5, etc.
  3. If we were to increase the numerator, what would happen to the fish's size?
  4. What if we decrease the numerator?

Step 3: Ask the User For a New Numerator

  1. Click on the Sensing tab.
  2. Bring out the "ask 'What's your name?' and wait" block.
  3. Attach it to the bottom of the code.

Step 4: Ask the User For a New Numerator

  1. Delete the text in this block.
  2. Type in "My size is 10/10. Change my numerator and see what happens!".
  3. Now, a text box will appear on the stage.
  4. The user can enter any whole number as the new numerator.

Discussion: The Size Equation

  1. We need to write an equation that will change our sprite's size as a fraction of ?/10.
  2. In Scratch, sizes are represented by a percentage.
  3. At full size, a sprite is 100%.
  4. At half size, it is 50%.

Discussion: The Size Equation

  1. We told our user that our sprite's size can be considered 10/10.
  2. If they entered "2", they would want to see our sprite at 2/10 of its size.
  3. 2/10 is the same as 20/100, which is 20%.
  4. 2 x 10 = 20
  5. So, we need to set the fish's size to: (answer) x 10.

Step 5: Change the Fish's Size

  1. Click on the Looks tab.
  2. Bring out a "set size to 100%" block.
  3. Attach it to the bottom of the code.

Step 6: Multiply the Answer by 10

  1. Click on the Operators tab.
  2. Bring out the "( ) * ( )" block.
  3. Attach it inside of the "set size to '100%" block.

Recap: Multiplication in Scratch

  1. In coding, multiplication is done with a * symbol. This is because the multiplication "x" that we are used to using does not exist on the keyboard! So, 2 * 4 is the same as 2 x 4.

Step 7: Multiply the Answer by 10

  1. Click on the Sensing tab.
  2. Bring out the "answer" block.
  3. Snap it in the left side of the "( ) * ( )" block.

Step 8: Multiply the Answer by 10

  1. Click in the right side of the "(answer) * ( )" block.
  2. Type 10.
  3. Discuss this new equation together as a class.

Test Your Work

  1. Make sure that your code matches the correct code.
  2. Click on the green flag.
  3. Enter a whole number for the numerator.
  4. What happens?
  5. Why?

Step 9: Display the New Size as a Fraction

  1. Let's have the fish say what it's new size is as a fraction.
  2. Click on the Looks tab.
  3. Bring out a "say 'Hello!' for 2 seconds" block.
  4. Change the '2' to a '4'.

Prep: The "join 'apple' 'banana'" Block

  1. We have used the "say" block before to display a line of text.
  2. We have also used it to display a value.
  3. The "join" block allows us to combine text with a value block!

Step 10: Display the New Size as a Fraction

  1. Click on the Operators tab.
  2. Bring out a "join 'apple' 'banana'" block.
  3. Snap it inside of the "say" block.

Step 11: Display the New Size as a Fraction

  1. Click on the Sensing tab.
  2. Bring out the "answer" block.
  3. Snap it in the left side of the "join" block.
  4. Remember that the "answer" block holds on to the user's numerator.

Step 12: Display the New Size as a Fraction

  1. Click in the right side of the "join 'answer' 'banana'" block.
  2. Delete the "world" text.
  3. Type in "/10".

Test Your Work

  1. Make sure that your code matches the correct code.
  2. Click on the green flag.
  3. Enter a whole number for the numerator.
  4. What happens?
  5. Why?

Step 13: Loop Forever

  1. Our app works, but we have to keep clicking the green flag to try another size.
  2. Let's use a forever loop to make it repeat all of these steps forever.
  3. Click on the Control tab.
  4. Bring out a "forever" loop.
  5. Wrap it around all of the code under the "when green flag clicked" block.

Test Your Work

  1. Make sure that your code matches the correct code.
  2. Click on the green flag.
  3. Enter a whole number for the numerator.
  4. What happens?
  5. Does the fish's size go back to normal?
  6. Does it ask us for a numerator again?
  7. Why?

Discussion

  1. How are sprite sizes represented in Scratch?
  2. How does our size equation work? What does it do?
  3. What does the "join" block do?
  4. What is a loop?
  5. What is a forever loop?

Challenge

  1. What happens when we change the denominator?
  2. How do we make the fish spin in a circle after the user gives an answer?

Good job! Time to submit your work to your teacher.

  1. Click "remix", then click "share"
  2. Copy the Scratch project link
  3. Go to your Google Classroom
  4. Find the correct assignment
  5. Paste the Scratch project link
  6. Click "Add link"

Unleash the power of Scratch 3!


Become a coding super-genius and create incredible projects with Scratch 3 - the newest version of the most powerful coding language for kids!

This beautifully illustrated, hilariously written, and delightfully engaging step-by-step guide is designed for kids (ages 8+) to learn the fundamentals of coding and apply them to amazingly innovative projects. Readers will learn to use the incredible new features of Scratch 3 to build projects that not only teach them to code, but also inspire them to pursue today's most exciting frontiers of technology:

  • Artificial Intelligence
  • Video Game Bots
  • Machine Learning
  • Augmented Reality
  • Multiplayer Computer Games