1 of 9

Unit 3 Lesson 8 part 2

Creating Functions with Parameters

2 of 9

To do: December 2

Log into your Code.org account.

Open the 2019-20 Unit 3 Lesson 7 bubble 10 - be ready to share.

3 of 9

To do: December 2

In the following procedure, the parameter str is a string and the parameter num is a number.

PROCEDURE printArgs(str, num)

{

DISPLAY(num)

DISPLAY(str)

DISPLAY(num)

}

Consider the following code segment.

printArgs("**", 1)

printArgs("*", 2)

What is displayed as a result of executing the code segment?

a) 1 * 1 2 ** 2

b) 1 ** 1 2 * 2

c) * 1 * ** 2 **

d) ** 1 ** * 2 *

4 of 9

To do: December 3

In the following procedure, the parameter str is a string and the parameter num is a number.

PROCEDURE printArgs(str, num)

{

DISPLAY(num)

DISPLAY(str)

DISPLAY(num)

}

Consider the following code segment.

printArgs("**", 1)

printArgs("*", 2)

What is displayed as a result of executing the code segment?

a) 1 * 1 2 ** 2

b) 1 ** 1 2 * 2

c) * 1 * ** 2 **

d) ** 1 ** * 2 *

5 of 9

DISPLAY command

  • The DISPLAY command is an AP Exam pseudocode command which displays output
  • When it prints a string, the double quotes are not shown (similar to JS write() command)
  • After printing output, it adds a white space but NOT a newline.

6 of 9

Homework

  • Complete in Code.org 2019-20 Unit 3 Lesson 7
    • Bubbles 2-9 in pairs
    • Bubble 10 individually - Use at least 3 different colors - Use moveTo command at least once
  • Khan Academy - Defining a procedure article and 4 questions

7 of 9

function drawHeart(x, y, color, size)

8 of 9

Complete using pair programming

  • 2019-20 Unit 3 Code.org Lesson 8 Bubbles 3-9, 10-15

randomNumber(min, max) —> returns a number between min and max, inclusive

drawFish(randomNumber(10,100),randomNumber(0,255),randomNumber(0,255),randomNumber(0,255));

function drawFish(size, red, green, blue)�{

// function defined

}

9 of 9

Homework

  • 2019-20 Unit 3 Code.org Lesson 8 Bubbles 3-9, 10-12
  • Khan Academy Reading and Exercises - Procedures with Parameters