Module 2: Programming Basics with Scratch
In the previous module, you got a glimpse of programming logic in the form of JavaScript. We'll now dive deeper into the fascinating and often confusing world of programming.
This module is one of the most important in the prework, as well as one of the most challenging. Push yourself to put in the time and effort necessary to complete it fully!
The Challenge of Programming
One of the challenges of programming is the fact that computers are very, very dumb. Much of the complex logic and layered thinking that we humans take for granted is completely bewildering to even the most complex computers.
Along the same lines, the art of coding and programming is principally focused on taking complex ideas and breaking them down into simple instructions that a computer, machine, or browser can interpret. Therefore, coding requires proficiency in two components that are needed to translate ideas into machine-language: computer syntax and computerthink.
Computer Syntax
Every coder must learn the syntax that a computer understands. Syntax is sort of like the grammar and punctuation of machine-speak. It's like knowing that every sentence has a subject and a predicate, or that every sentence should begin with a capital letter and end with a punctuation mark.
Programming languages come with their own rule sets. A rule set might specify a special meaning for brackets or symbols, for example, or specify a particular method for using code across different files.
Throughout the course you'll be learning a ton of syntax. It may seem tricky at first, but it will become second nature in no time.
Computerthink
Coding means converting your ideas into computerthink. Unlike humans, computers are limited in their ability to work with anything abstract, vague, or general. In order for computers to understand complex problems, they must be broken down into small, discrete blocks of logic.
Think Like a Computer
Take, for instance, the following challenge: how do you make a peanut butter and jelly sandwich? You might start with a list that looks like the following:
- Get two slices of bread, peanut butter, and jelly.
- Get utensils and a plate.
- Slather peanut butter and jelly on each slice of bread.
- Put the two slices of bread together.
Simple, right? Well, there's a little more to it when it comes to computerthink. Take item 3, for instance: "Slather peanut butter and jelly on each slice of bread." Whereas a human would probably understand this instruction, a computer needs to be given some additional information, including:
- How many times do you slather?
- In what direction do you slather?
- What amount do you slather?
- What utensil do you use to slather?
- Which slice of bread do you slather first?
As you will find out, learning to code often requires one to think far more slowly than we are generally accustomed. Instead of rushing, the computer forces you to slow down and reason out your thoughts in a series of detailed steps.
Scratching the Surface
A great way to familiarize yourself with programming logic is to use a visually oriented language like Scratch, which disguises coding syntax as draggable blocks. Even though you don't "write" code with Scratch, a lot of thought still goes into piecing together the directions that the computer needs to take. Just look at some of the amazing games other users have made with Scratch!
Whether or not games interest you, the underlying logic that goes into creating them can be applied to other software development problems (e.g., what should happen if the user clicks a button). Let's use Scratch to build our own game to ultimately help us better understand how computers think. While you're free to make anything you like, we recommend taking on one of these examples:
- A Game of Cat and Mouse (Challenge)
- Get the Cheesy Puffs! (Recommended)
- Button Click Exercise (Easy)
This is your first real challenge as a developer. Take the time to independently learn what it takes to build these applications, and treat this as a serious endeavor. The logic on which these games are based is very similar to the logic you'll be dealing with later in the course. If you're new to programming, the recommended and challenge activities may take up to 15 hours to complete.
Instructions
-
Go to the Scratch website and create a new (free) account.
-
Read the Getting Started with Scratch guide to learn the basics of how Scratch works.
-
Create a rough outline that maps out all aspects of the game you chose to build. In your outline, consider answering the following:
-
What are the rules of the game?
- What has to happen before other steps can happen?
- Will you need to repeat certain steps?
- Are some steps based on a condition (if this, then that)?
- What information (variables) do you need to keep track of?
-
When would the values of those variables change?
-
When you have a rough outline, begin the process of coding it out in Scratch. Your final game should include the following functionality:
-
A Game of Cat and Mouse
- Users can move the cat left and right with the arrow keys.
- Users can press the spacebar to shoot a projectile.
- Mice fall from the sky at random locations.
- If a mouse reaches the bottom, the player loses a life.
- If the player shoots a mouse, the mouse is deleted and the player gets a point.
- When a player reaches 0 lives, they lose.
-
Get the Cheesy Puffs!
- Users can move the cat up, down, left, and right by using the arrow keys.
- If the player touches the cheesy puffs, their score goes up by 1 and the puffs move to a random location.
- When the player reaches a score of 10, a victory image is shown and the game ends.
-
Button Click Exercise
- A variable that starts the game at 0.
- A button that increases the value of the variable by 1.
- A button that decreases the value of the variable by 1.
- A button that resets the value of the button back to 0.
Helpful Hints
- Look at other games found on the website, and then view the code to get inspiration for your own project. (Borrowing from the work of other developers in the open source community is a great habit to get into, as you'll be doing the same repeatedly as a developer.)
- Don't get discouraged if you can't complete this activity. In the boot camp, you will learn that perfection doesn't come easily, and sometimes it can wait in favor of having something that works!
- Stay motivated! This activity is very much in line with the sorts of challenges you will face in class. At times you will be frustrated, but don't give up––you'll only cheat yourself out of a good learning opportunity.
Good luck!
Resources
© 2019 Trilogy Education Services