1 of 21

Unit 4

Turtle Programming part 3

2 of 21

To do: November 17- Warm-up #1

a <- true

b <- false

c <- true

b <- ( NOT b ) OR b AND c

c <- b AND a

DISPLAY ( a )

DISPLAY ( b )

DISPLAY ( c )

3 of 21

To do: November 17 - Warm-up #2

a <- true

b <- false

c <- true

a <- NOT ( a OR b ) AND c

b <- c AND a

DISPLAY ( a )

DISPLAY ( b )

DISPLAY ( c )

4 of 21

Revisit 3x3 Square Grid

Take out your IN.

Now that you can create functions, you will draw the 3x3 square grid using functions.

Plan with your partner which functions you will create.

One of the functions should be drawSquareGrid() which will be called on once.

5 of 21

Intro to Top-Down Design

  • One method for approaching programming problems is called “Top-Down Design” or “Stepwise Refinement”.
  • This strategy is an informal way of repeatedly dividing a system into simpler subsystems.

6 of 21

Example of Top-Down Approach

7 of 21

8 of 21

Code.org '19-20 Unit 3 Lesson 6 bubble 3

Complete Bubble 3 together. Write out the names of the functions you created in your IN.

One of the functions should be drawSquareGrid() which will be called on once.

9 of 21

Code.org '19-20 Unit 3 Lesson 6 bubble 3

Complete Bubble 3 together. Write out the names of the functions you created in your IN.

When you are done, complete bubble 2.

10 of 21

Go over homework

  • Complete Code.org '19-20 Unit 3 Lesson 5 Bubbles 3-5, 7-10
  • Complete Functions and Abstraction worksheet - turn into Hub
  • Complete AP Classroom Conditionals Practice part 2
    • Show work for each problem in IN and submit image/pdf to Hub

Boolean expressions / Conditional statements quiz on Thursday

11 of 21

Unit 4 Lesson 9 - Warm Up

Prompt

In the Hub, click on the link to the song lyrics of "Wake me up when it's all over" using 2 different styles.

  • In Style 1, what line of the song do you sing after line 09? What about in Style 2?
  • Style 2 uses fewer lines to write. Are there fewer lyrics to sing?

12 of 21

Unit 4 Lesson 9 - Warm Up

Prompt

3. What are the benefits of writing a song in Style 2?

Style 2 is an example of an abstraction.

An abstraction is the process of reducing complexity by focusing on the main idea. By hiding details irrelevant to the question at hand and bringing together related and useful

details, abstraction reduces complexity and allows one to focus on the idea.

13 of 21

14 of 21

Unit 4 Lesson 9 - Activity

What is a function?

A function is a named group of programming instructions that can be called upon from different parts of the program but only need to be defined once.

Functions are reusable abstractions that reduce the complexity of writing and maintaining programs.

15 of 21

Function: a named group of programming instructions. Also referred to as a “procedure”.

Function Call: a command that executes the code within a function definition

Unit 4 Lesson 9 - Wrap Up

16 of 21

Unit 4 Lesson 9 - Activity

Functions Explore (individually)

Do This:

  • Navigate to Lesson 9, Bubble 1 on Code Studio
  • Call on singChorus() twice

17 of 21

Unit 4 Lesson 9 - Activity

Bubble 4

  • On what line(s) is the updateScreen functions being declared?
  • On what lines is the updateScreen function being called?
  • Modify program so the text clicks is displayed after the number.

18 of 21

Unit 4 Lesson 9 - Activity

Bubble 5

  • How does the newly added updateScreen function help keep your code better organized or reduce the amount of repeated code?

19 of 21

Unit 4 Lesson 9 - Wrap Up

The updateScreen() Pattern

Code (Block)

Code (Text)

var count = 0;

updateScreen();

onEvent(“upButton”, “click”, function(){

count = count + 1;

updateScreen();

});

onEvent(“downButton”, “click”, function(){

count = count - 1;

updateScreen();

});

function updateScreen(){

setText(“countLabel”, count);

if(count > 20){

setProperty(“countLabel”, “text-color”, “green”);

}

}

20 of 21

21 of 21

Homework

  • Complete '19-20 Unit 3 Lesson 6 bubble 3 (3x3 grid using functions)
    • Submit image of names of functions you used to complete the 3x3 grid
  • Study for Boolean expressions / Conditional statements quiz on tomorrow

Tomorrow, we'll complete Lesson 9 together.