1 of 14

Unit 4 Lesson 9

Functions Explore

2 of 14

To do: November 18

  • Look up your ZipGrade ID.
  • Make sure you have a pencil or erasable pen
  • Pick up a divider.

3 of 14

To do: November 18

The diagram to the right shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output.

For which of the following input values will the circuit have an output of true?

A. A = true, B = true, C = true, D = false

B. A = true, B = false, C = false, D = false

C. A = false, B = true, C = true, D = true

D. A = false, B = false, C = true, D = true

4 of 14

To do: November 18

The diagram to the right shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output.

For which of the following input values will the circuit have an output of true?

A. A = true, B = true, C = true, D = false

B. A = true, B = false, C = false, D = false

C. A = false, B = true, C = true, D = true

D. A = false, B = false, C = true, D = true

5 of 14

To do: November 18

In a certain country, a person must be at least 16 years old to drive a car and must be at least 18 years old to vote. The variable age represents the age of a person as an integer. Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to vote, and evaluates to false otherwise?

I. (age ≥ 16) AND (age ≤ 18)

II. (age ≥ 16) AND (NOT(age ≥ 18))

III. (age < 18) AND (NOT(age < 16))

a) I only b) II only c) III only d) II and III e) I, II and III

6 of 14

To do: November 18

In a certain country, a person must be at least 16 years old to drive a car and must be at least 18 years old to vote. The variable age represents the age of a person as an integer. Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to vote, and evaluates to false otherwise?

I. (age ≥ 16) AND (age ≤ 18)

II. (age ≥ 16) AND (NOT(age ≥ 18))

III. (age < 18) AND (NOT(age < 16))

a) I only b) II only c) III only d) II and III e) I, II and III

7 of 14

Go over 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

8 of 14

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.

9 of 14

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

10 of 14

Unit 4 Lesson 9 - Activity

Unit 4 Lesson 9 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.

11 of 14

Unit 4 Lesson 9 - Activity

Unit 4 Lesson 9 Bubble 4

  • Create an updateScreen function to replace the duplicate code in the program and make two calls to the function
  • How does the newly added updateScreen function help keep your code better organized or reduce the amount of repeated code?

12 of 14

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”);

}

}

13 of 14

Homework

  • Complete goFormative - U4L09 Functions Explore

5th period: Quiz is tomorrow (Friday)

14 of 14

Conditionals and Booleans Quiz

8 MC questions