Overview of Code.org’s Hour of Code activity
Our activity is a set of 20 self-guided puzzles that teach the basics of computer science for users with no prior experience. In each puzzle, students write a program that gets a character through a maze. The activity uses Blockly, a visual programming language that has blocks you drag and drop to write programs. The activity includes instructional videos before puzzles #1, 6, 10, 14, 18, and a wrap-up video after the last puzzle. The characters in our activity are from the popular kids’ games Angry Birds and Plants vs. Zombies.
Check out the educational standards our activity addresses here (Common Core, NGSS and CSTA standards). And as much as we designed this activity to teach basic computer science, we’re aiming for students to walk away thinking that computer science is fun, approachable, and relevant to their lives.
Our activity is one of the lessons from our free K-8 Intro to Computer Science Course. If you and your students enjoy our Hour of Code activity, consider teaching the whole course.
Prep for the Hour of Code
Right before your class period
During the Hour of Code in your classroom
When your students come across difficulties
What to do if a student finishes early?
Adjustments for K-2 Teachers
But, really, what do I need to know about computer science to teach the Hour of Code?
A program is a set of instructions for your computer to follow. You build a program using commands. Here is a description of what each command in our activity does:
The move forward block advances a character one space on the grid of the maze.
The turn left block makes the character face to the left. It does not advance the character any spaces on the grid
The turn right block makes the character face to the right. It does not advance the character any spaces on the grid.
The repeat times block is called a loop in computer science. Whatever blocks you put inside this block will be repeated however many times you write in the top of the block. For example, if you put a “move forward” block followed by a “turn left” block inside the repeat times block and set it to repeat for 3 times, this is what will run: move forward, turn left, move forward, turn left, move forward, turn left.
The repeat until block is also a loop. It will repeat (or loop) whatever command you put inside of it until it reaches the end goal or runs into a wall in the maze. This block is useful in cases where you don’t know exactly how many times you need something to repeat until a specific end point.
The if block makes a decision for the computer. It checks to see if the statement on the top is true, and if it is true, the character will do whatever commands you put inside the block. If the statement on the top is not true, the character will do nothing. Note: when you click on the words “to the left”, it reveals a drop-down menu where you can choose other statements, the character can check: if there’s a path to the right or if there’s a path ahead.
The if else block is very similar to the if block, but instead of doing nothing if the statement on the top is true, you can have it do an action or set of actions by placing commands in the “else” spot. For example, if you put a “move forward” block in the spot where it says “do” and you put a “turn left” block where it says “else”, the character will check to see if there’s a path ahead, and it there is, it will move forward, and if there’s not a path ahead, it will turn left. Note: there is also a drop-down menu in this block, just like the if block.
Here are the solutions for each puzzle with notes. Some notes include prompting questions for students, so you can walk around the classroom while students complete the activity and help students one on one who are struggling.
Some students may have trouble finding the “Run Program” button. It’s the orange button below the maze.
Some students may have trouble connecting the blocks, so this puzzle reinforces that skill without adding new concepts.
This puzzle introduces the turn block. And now students must avoid obstacles, in this case, a crate of TNT.
This puzzle practices using both left and right turns.
This is the most difficult puzzle that practices the basic sequence of commands. If students get stuck, ask them to put themselves in the character position and what would they need to do to get to the pig?
This program repeats the “move forward” block 5 times to reach the pig. Students might be tempted to just use 5 “move forward” blocks but it’s important to know how to be efficient in computer science. Ask them to imagine if you needed to move forward 1,000 spaces.
The bird has to turn right and then perform the repeat block to get to the pig.
This puzzle needs 2 repeat blocks, and you have to change the number value in the first block from “5” to “4”. To do that, click on the number “5” and make sure it’s highlighted. Then hit the “delete” key on your keyboard and then press “enter” on your keyboard or click on the workspace.
Ask students to think about the solution using just “move forward” and “turn” blocks. Then ask them if they see any patterns that could be repeated. The repeat block is already out on the workspace to encourage students to use it.
This repeats the move forward command until the bird reaches the pig.
Once again, students should be encouraged to look for patterns to decide what actions to repeat.
Some students might write very long programs and then be tempted just to keep adding to them to try and fix them. You might tell them to start with a fresh workspace and ask them to think about the individual commands to get to the sunflower. Then identify a pattern and put those commands inside a repeat block.
This puzzle reinforces concepts from the last puzzle.
For this puzzle, students only have to fill in one block: they have to put a “turn left” block inside the “if” block. This program tells the zombie to repeatedly move forward and every step forward, the zombies check if there’s a path to the left. If the zombie finds a path to the left, it will turn left, and then keep moving forward.
Now, students must re-create code similar to the last level, but this time turning to the right. Ask students to think about what turns are necessary for the zombie to reach the sunflower. They’ll answer “all right-hand turns” and you can ask them to write code that makes the zombie move forward and only turn right when there’s a path to the right.
This is the same code from puzzle 14. You can point out to students that by using the “if” and “repeat” blocks, this program can be used to solve multiple different mazes (rather than just a sequence of move and turn blocks that will only solve a specific path.)
This puzzle is for practice and reinforcement with the “if” and “repeat” blocks.
Ask students how the zombie should get to the sunflower with the fewest number of turns. Then ask them are they left or right hand turns? They’ll say all left-hand turns, and you can tell them that the “if else” block can help you make decisions like that. If there’s a path ahead, move forward, and otherwise, turn left.
This is reinforcing to the last puzzle.
Ask students to read the code that is already out on the workspace. “If there’s a path ahead, what action would you want the zombie to do? Then, if there’s a path to the left, what do you want the zombie to do? And if there’s not a path to the left, what should you put in the “else” spot?” The zombie will move forward IF there’s a path ahead, otherwise it will decide IF there’s a path to the left and then do one of two actions (turn right or turn left) based on that decision.