Change text size:  

Students: do this first!
  1. Mute your computer.
  2. Open a web browser and go to cca.ac/eet for the starter project.
Overview

  1. Today we are going to code a game that uses fractions! Instead of writing our own fraction problems, we will code the parrot to come up with its own problems. To do this, we will learn about variables!

Step 1: Setting up the Game Loop

  1. Click on the Events tab.
  2. Bring out a "when green flag clicked" block.
  3. Now, any code that gets attached to this block will only happen when the green flag is clicked.

Step 2: Setting up the Game Loop

  1. Click on the Control tab.
  2. Bring out a "forever" block.
  3. Attach it to the rest of your code.
  4. The "forever" block is a loop. Can you explain what a loop does?

Recap

  1. So far, we only have two blocks. We want to make sure that the game starts only when the green flag is clicked. We also want to make sure that the game runs forever, so that it doesn't stop while we are playing it!

Recap

  1. Now that we have that finished, we can start coding the game inside the "forever" block.

Step 3: Setting up the Game

  1. Click on the Looks tab.
  2. Bring out a "say 'Hello' for '2' seconds" block.
  3. Change the "Hello" to the following:
  4. "There are 16 lines on this number line."
  5. Attach the block to the rest of your code.

Step 4: Placing the Parrot

  1. Click on the Motion tab.
  2. Bring out a "go to x:'-185' y:'50'" block.
  3. Attach it to the rest of your code.
  4. If the numbers on your block are not -185 and 50, change them by clicking on the number and typing in the correct number.
  5. This block will make sure that the parrot is placed above the 0 on the number line.

Recap: What is a Variable?

  1. Sometimes, we need the computer to remember information. To do this we use variables. A variable is a block of code that can save information for us. In this program, we have created a variable named "numerator". We will use this variable to let the computer choose random numerators. This way, the computer can make up problems for us to solve.

Step 5: Setting the Variable

  1. Click on the Variables tab.
  2. Bring out a "set numerator to '0'" block.
  3. Attach it to the rest of your code.

Step 6: Step 6: Setting the Variable

  1. Click on the Operators tab.
  2. Bring out a "pick random '1' to '10'" block and place it on top of the '0'.
  3. Change the numbers to "'1' to '8'".

Step 7: Getting Input

  1. Click on the Sensing tab.
  2. Bring out an "ask 'What's your name?' and wait" block.
  3. Change the question to the following:
  4. "How many lines should I fly over to get to the fraction above?"
  5. Attach the block to the rest of your code.

Test your work

  1. Click on the green flag to test out your code! What do you think will happen when you click on the green flag?
  2. After the parrot finishes talking, the numerator on the fraction should randomly change!

Moving The Parrot

  1. Next, we are going to make a math problem for the computer to solve for us! The answer will tell the parrot how many steps to move for it to go where we ask it to.

Step 8: Moving The Parrot

  1. Click on the Control tab.
  2. Bring out a "repeat" block.
  3. Place it under the "ask" block.

Step 9: Moving The Parrot

  1. Click on the Operators tab.
  2. Bring out a "( ) * ( )" block.
  3. Replace the "10" in the repeat block with the "( ) * ( )" block.
  4. Enter '40' on the left side of the "( ) * ( )" block.

Step 10: Moving The Parrot

  1. Stay on the Operators tab.
  2. Bring out a "( ) / ( )" block.
  3. Place it on the right side of the "( ) * ( )" block.
  4. Enter '16' on the right side of the "( ) / ( )" block.

Step 11: Moving The Parrot

  1. The next number in your math problem will be the answer to the question from your "ask" block.
  2. Click on the Sensing tab.
  3. Bring out an "answer" block.
  4. Place it on the left side of the "( ) / ( )" block.

Step 12: Moving The Parrot

  1. Click on the Motion tab.
  2. Bring out a "move '10' steps" block.
  3. Attach it inside the "repeat" block.

Recap

  1. In the last few steps, you programmed the code that makes the parrot move! The computer will answer the math problem that you created. Then, the answer to that problem will be the number of times that the parrot will move 10 steps.

Test your work

  1. Click on the green flag to test out your code! What do you think will happen when you click on the green flag?
  2. Using your math skills, you can control which line the parrot lands on! Now, we need the parrot to tell us whether or not we answered the problem correctly. We will use if-thens to make that happen.

Step 13: Setting Up If-Thens

  1. Now that our question has been asked, we can use if-thens to check if the answer is right.
  2. Click on the Control tab.
  3. Bring out an "if-then-else" block.
  4. Attach it to the rest of your code.

Step 14: Setting Up If-Thens

  1. Click on the Operators tab.
  2. Bring out an "( ) = ( )' block.
  3. Attach it inside of the if-then.

Step 15: Setting Up If-Thens

  1. Stay in the Operators tab.
  2. Bring out a "( ) * ( )" block and place it on the right side of the = sign.
  3. On the right side of the "( ) * ( )" block, enter '2'.

Step 16: Setting Up If-Thens

  1. Click on the Variables tab.
  2. Bring out a "numerator" block.
  3. Place it on the left side of the "( ) * ( )" block.

Step 17: Setting Up If-Thens

  1. Click on the Sensing tab.
  2. Bring out an "answer" block.
  3. Attach it to the left side of the = sign.

Step 18: Using Conditional Statements

  1. Click on the Looks tab.
  2. Bring out a "say 'Hello' for '2' seconds" block.
  3. Change the "Hello" to the following:
  4. "Correct!"
  5. Attach the block to the IF part of our conditional statement.
  6. Now, IF you answer correctly, the computer will know to tell you that you got the problem right!

Step 19: Using Conditional Statements

  1. Click on the Looks tab.
  2. Bring out a "say 'Hello' for '2' seconds" block.
  3. Change the "Hello" to the following:
  4. "Sorry, try again."
  5. Attach the block to the ELSE part of our conditional statement.
  6. Now, when your answer is anything ELSE than the answer, the computer will know to tell you that you got the problem wrong.

Test Your Work

  1. Congratulations! You have completed this project! Click on the green flag and test your work! The parrot should now ask us random fraction problems. The parrot will also tell you if you got the problem right or wrong.

Discussion

  1. What does the "if-then-else" block do?
  2. Why do we make the parrot return to (-185, 50) each time we go through the loop again?
  3. What is a variable and when do we use a variable in our project?

Challenge

  1. How can we make the parrot flap its wings when it flies?
  2. If we want to ask about a different denominator, what code has to be changed?

Good job! Time to submit your work.

  1. Click "remix"
  2. Your project is now saved!