The Hour of Code is a global movement introducing tens of millions of students worldwide to computer
science, inspiring kids to learn more, breaking stereotypes, and leaving them feeling empowered.
Most of the fourth graders have already had experience coding before. I am excited to introduce them to Scratch 3.0 from MIT, a block programming environment that lets you create interactive stories, animations and games. This is the first version of Scratch that works on an iPad. In the past, the students were exposed to more structured programming environments. Because this platform is a blank canvas that allows students to create whatever they can imagine, I want them to understand "how to think like a computer", so they can be more successful. All tasks must be broken down into small chunks that are easy to follow, and impossible to get wrong. And you have to be very detailed and specific. Your code does exactly what you tell it to.
| |
Today the students are going to write a math game their classmates can play. Try and make it challenging to see if you can stump them. Here are the basic components of the code:
- The Ask () and Wait block is a Sensing block. It asks whatever you specify and then waits for an answer. When run, there will be an input box at the bottom of the screen. Scratchers can input text into it and submit it, and the input is stored in the Answer block. The Answer block automatically updates to most recent input.
- The () = () block is an Operators block and a Boolean block. The block checks if the first value is equal to the other value. If the values are equal, the block returns true; if not, false. This block is not case-sensitive.
- The If () Then, Else block is a Control block and a C block. The block will check its boolean condition. If the condition is true, the code held inside the first C (space) will activate, and then the script will continue; if the condition is false, the code inside the second C will activate (unlike the If () Then block).
What if you want the Scratcher to guess until they get the right answer. Then you can use:
- the Repeat Until () block is a Control block and a C block. Blocks held inside this block will loop until the specified boolean statement is true, in which case the code beneath the block (if any) will execute. This loop is in similar nature to a while loop in some other programming languages.
You can add additional questions immediately following the existing code. The next question should be asked once the Scratcher gets the answer to the previous question right.