← CS50: Introduction to Computer Science

Week 0: Scratch

Computational thinking before a single line of text-code: binary, abstraction, and algorithms taught in click-together blocks.

8 topics · 30 questions

Each topic is a path, not a menu: work down it in order and every question builds on the one above. Click any of them to watch the answer draw itself.

Computational Thinking and Problem Solving

  1. How it worksHow does a computer scientist turn a vague goal into a precise list of inputs, outputs, and steps?
  2. Worked exampleWalk me through turning 'get ready for school on time' into a precise step by step algorithm.
  3. Going furtherWhat happens to a problem's difficulty once you can name its exact inputs and outputs?
  4. Common mistakeWhy isn't computational thinking the same skill as memorizing programming syntax?
Your turn1 of 2
A vague goal is broken down into 8 major steps, and each major step is further broken into 6 precise sub-steps. How many total sub-steps does the finished algorithm have?

Representing Numbers in Binary

  1. How it worksHow does flipping a row of light switches on and off let you count upward in binary?
  2. How it worksHow does an odometer rolling from 9 back to 0 explain why binary carries the same way decimal does?
  3. Worked exampleFind the binary representation of the decimal number 13.
  4. Common mistakeWhy isn't binary secretly a harder way of writing the same number as decimal?
Your turn1 of 2
How many distinct values can a binary number with 12 bits represent?

ASCII, Unicode, and Text as Bits

  1. How it worksHow does ASCII map the letter A to the number 65 and every other keyboard key to its own number?
  2. Worked exampleFind the ASCII decimal value stored for the capital letter H.
  3. Common mistakeWhy doesn't a computer actually store the letter A as a tiny picture of the letter A?
Your turn1 of 2
In ASCII, the capital letter A has decimal value 65. What decimal value does the capital letter sitting 17 letters after A in the alphabet have (for example, k=2 would be C)?

RGB and Representing Color

  1. Worked exampleFind the RGB values that mix to produce pure yellow on a screen.
  2. Common mistakeWhy isn't mixing light with red, green, and blue the same as mixing red, yellow, and blue paint?
  3. Going furtherWhat happens to a color's RGB values as you fade an image toward black?
Your turn1 of 2
A pixel's channel value is 181 out of 255. Fading this channel 40 percent of the way to black multiplies it by 0.6. What is the new value?

Abstraction and Black-Box Thinking

  1. How it worksHow does wrapping a set of steps inside one named block let you reuse them without rethinking them?
  2. Going furtherWhat happens to a program's readability when it never wraps repeated steps in a block?
  3. Ties togetherHow does the abstraction inside a Scratch block foreshadow what a function will do in C?
Your turn1 of 2
A block of 8 steps is wrapped into one named block and that named block is called 8 times in a program. How many total step-executions happen across all the calls?

Algorithms, Pseudocode, and Running Time

  1. How it worksHow does writing an algorithm in plain-English pseudocode force you to spell out every step?
  2. How it worksHow does counting the steps an algorithm takes let you compare two different solutions fairly?
  3. Worked exampleWalk me through counting the steps a pseudocode algorithm takes to find the biggest number in a list of 5.
  4. Common mistakeWhy isn't the fastest-looking algorithm on a small list always the fastest one on a huge list?
  5. Going furtherWhat happens to an algorithm's running time when the size of its input doubles?
Your turn1 of 2
An algorithm that finds the biggest number in a list must examine every element exactly once. How many examinations does it make on a list of 36 numbers?

Conditionals and Loops in Scratch

  1. How it worksHow does an if-else block guarantee that exactly one of its two branches ever runs?
  2. Common mistakeWhy isn't an if-else block in Scratch just two separate if blocks stuck together?
  3. Worked exampleWalk me through a Scratch script that makes a cat sprite bounce off the edge of the stage forever.
  4. Going furtherWhat happens to a loop if the condition inside it can never become true?
Your turn1 of 2
A 'repeat 21' loop in Scratch contains two blocks inside it: move 10 steps, then turn 15 degrees. How many total block-executions happen when the loop finishes?

Variables, Events, and Threads in Scratch

  1. How it worksHow does a variable act like a labeled box that a Scratch script can read from and write to?
  2. Worked exampleWalk me through a Scratch script that adds 1 to a score variable every time a sprite is clicked.
  3. Going furtherWhat happens when two Scratch scripts run as separate threads and both touch the same variable at once?
  4. Ties togetherHow does an event block like when green flag clicked foreshadow how a C program always starts inside main?
Your turn1 of 2
A Scratch score variable starts at 14. A sprite is clicked 33 times, and each click adds 1 to score. What is the score afterward?