Remember: To read code, go line by line, use the names as clues, run it by hand with small numbers, and check comments against the code.
Read and answer
Read the story, then answer.
A wall of linesMina opens Teo's Dance Party code, and a wall of lines fills the screen. Mr. Reyes says to read it like a recipe, one line at a time. She hunts for names, because a name in code is a clue, and she spots beat count, dance speed and moves. She finds a loop that repeats the dance, adding one to beat count each time, and she runs it on paper with small numbers: beat count starts at zero and goes up one, two, three, four, five. A note beside the loop says four moves per song, but the loop makes five. Notes in code are called comments. Mina changes the five to a four, and Bo dances four moves.
1
How should Mina start reading Teo's code?
Skip to the middleLine by line from the top, saying what each line doesChange things and hope
2
A name in code, like beat count, is a clue to what a box holds.
TrueFalse
3
Notes in code that explain it to people are called .
commentsloopsboxes
4
Run this tiny program in your head. What does it say at the end?
7124
5
In the tiny program, which line gives the box coins its start value?
set coins to zeroadd three to coinssay coins
6
The computer reads a comment and changes the answer because of it.
TrueFalse
Match, order and fix
7
Join each line of the tiny program to its job.
1set coins to zero
2repeat four times
3add three to coins
4say coins
Aruns what is inside four times
Bchanges the box each time round
Cshows what the box holds
Dgives the box its start value
8
Put Mina's way of reading code in order.
Check the comment against the code
Try one small change
Start at the top
Run it on paper with small numbers
Look for names that are clues
9
A note says four moves per song, but the loop makes five. What should Mina do?
Trust the note and ignore the loopDelete the note and say nothingCheck the note against the code, because the code is what runs
10
Beat count starts at zero and goes up one each trip. After five trips it holds .
11
Circle every good way to read code.
Read one line at a timeSkip to the middleChange one thing at a timeTrust every comment
12
With a grown-up, take a recipe or a game's rules. Write what two of its lines do.
13
Draw the box called coins, and write what it holds after each of the four trips round the loop.
Scan the code at the top to mark this sheet on screenTake a photo of your answers or type them. It is marked for you automatically, and your score is kept.