UNIT 3 – LESSON 5 Creating Functions.

Slides:



Advertisements
Similar presentations
AP Computer Science Principles Data Abstraction and Procedural Abstraction Curriculum Module.
Advertisements

Introduction to programming in the Java programming language.
Algorithms and Flowcharts
JavaScript: API’s, Parameters and Creating Functions with Parameters
AP CSP: Creating Functions & Top-Down Design
Creativity of Algorithms & Simple JavaScript Commands
Personality Test based on the Myers-Briggs Type Indicator
JavaScript/ App Lab Programming:
Reading Turnitin Reports
Computer Programming.
Broadcasting (Adding a new level)
HTTP AND ABSTRACTION ON THE INTERNET
Unit 3: Lesson 1 - The Need for Programming Languages
Vocabulary byte - The technical term for 8 bits of data.
UNIT 2 – LESSON 3 Encoding B&W Images.
THE NEED FOR DNS DOMAIN NAME SYSTEM
FOP: Buttons and Events
Unit 3 Lesson 4 & 5- Programming With Simple Commands / Creating Functions Day 26.
Functions and Top-Down Design
UNIT 2 – LESSON 6 ENCODE AN EXPERIENCE.
UNIT 2 – LESSON 2 TEXT COMPRESSION.
The Need for Programming Languages
The Need for Algorithms 2 days
APIs and Function Parameters
Looping and Random Numbers
AP CSP: Bytes, File Sizes, and Text Compression
RAPID RESEARCH DATA INNOVATIONS
Sending Bits on the Internet
Practice PT - Design a Digital Scene 3 days
Lesson 1: Buttons and Events – 12/18
Learning to program with Logo
DAY 2: Create PT: Make a Plan
LESSON 12 - Loops and Simulations
Lesson 2: Building Blocks of Programming
Graph Paper Programming
Fill the screen challenge!
Title of notes: Text Annotation page 7 right side (RS)
LESSON 14 - Building an App: Image Scroller
Lesson 16: Functions with Return Values
Log onto a computer first then ….
LESSON 13 – INTRO TO ARRAYS
Making Procedural Methods
UNIT 3 CHAPTER 1 LESSON 4 Using Simple Commands.
Creating Functions with Parameters
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
LearnZillion Notes: --This is your hook. Start with a question to draw the student in. We want that student saying, “huh, how do you do X?” Try to be specific.
Looping and Random Numbers
• Welcome to this assembly about Free Your Feet, the week-long walking challenge for secondary schools from UK charity Living Streets. • Who are Living.
Programming Basics - RobotC
Unit 3: Lesson 9-Looping and Random Numbers
Computational Thinking for KS3
RAPID RESEARCH DATA INNOVATIONS
Finding Trends with Visualizations
Topic 1: Problem Solving
Directions on using the Guided Reading Lesson Plan I have made the lesson plans and readers response example available for you to edit it and make.
Rapid Research - Format Showdown
Functions and Top-Down Design
Unit 3 lesson 2-5 The Need For Algorithms- Creativity in Algorithms – Simple Commands - Functions Day 18.
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
Tonga Institute of Higher Education IT 141: Information Systems
Unit 3: Lesson 1 - The Need for Programming Languages
Tonga Institute of Higher Education IT 141: Information Systems
Computational Thinking
Combining Like Terms.
Introduction to Python
The Writing Process.
Quiz: Computational Thinking
Mod 3 Lesson 2 Me First! Sorting
CMPT 120 Lecture 3 - Introduction to Computing Science – Programming language, Variables, Strings, Lists and Modules.
Active Reading Series: How to Critically Annotate
Presentation transcript:

UNIT 3 – LESSON 5 Creating Functions

VOCABULARY ALERT! Abstraction - Pulling out specific differences to make one solution work for multiple problems. Function - A piece of code that you can easily call over and over again. camelCase – a function name that starts with a small letter, then shows the next word with a capital letter, but no spaces

INTRODUCED CODE

Let’s talk about functions Let’s talk about functions. When you decide to write a function in JavaScript it's often because you recognize a pattern - a bit of code that you might need to use later, at a different point in the program. Remember with text-compression in Unit 2 you looked for phrases or letters that repeated. https://youtu.be/jofNR_WkoCE When you put that phrase in the dictionary you were defining a pattern to reuse. Then all occurrences of that pattern were replaced in the text. So if the compressed version looked like this: ☆listen_to★rain_☆on★window_pane Each special character was referring to a stored pattern in the dictionary. The dictionary, of course, is like the set of functions you define. Once you define it, you don't need to define it again. Calling a function is like using the special character in the compressed text - you want to call on a stored definition of something.

PURPOSE: In this lesson, you will learn to define and call procedures (in JavaScript, procedures are called “functions”) to create and give a name to a group of commands for easy and repeated use in your code.

WHY USE FUNCTIONS? these functions can make YOUR code clearer or more concise.

To extend their functionality, nearly all programming languages provide a means for defining and calling new commands which programmers design to fit the needs of the problems they are trying to solve. Defining functions is an example of how computer scientists use abstraction to solve problems.

A programmer will design a solution to a small, well-defined portion of the task and then give a name to the associated code. Whenever that problem arises again, the programmer can invoke the new function by name, without having to solve the problem again. 

In the previous lesson we created simple turtle drawings using only four commands. At some point you probably wished that more commands were available to you. Describe a command you wanted to be able to use and explain why you wanted to use it.

SO YOU MAY HAVE SAID: A command that turns the turtle to the right A command that moves forward more than one space A command that creates a repeated pattern or shape You may also just wish for different colors, curved lines, etc.

Programming languages will always have some commands that are already defined, but there will be many instances when the exact command we want isn’t available. Today we’re going to start exploring a powerful feature called FUNCTIONS of most programming languages that will allow us to overcome this issue and create commands of our own.

EVERYONE IS DOING YOUR OWN WORK IN CODE STUDIO, BUT YOU CAN WORK WITH YOUR PARTNERS TO FIGURE THIS OUT. REMEMBER – WE ARE USING FUNCTIONS AND CALLING THEM OVER AND OVER.

YOU NAME FUNCTIONS USING WHAT IS CALLED camelCase – this name should make sense to the programmer. The computer doesn’t care what you call it! You cannot start function names with a number. YOU CANNOT START FUNCTION NAMES WITH A NUMBER!!!!

What are the benefits of being able to define and call functions in a program. Who specifically gets to enjoy those benefits? programs are easier to read and write functions remove the need to repeat large chunks of code functions break the program into logical chunks The person programming and any other human reading the program enjoys these benefits. Important to note: functions do not make the program easier (or harder) for the computer to run or understand -- it must still run all of the same commands as before.

How is the use of a function an example of abstraction How is the use of a function an example of abstraction? (College Board Big Idea!) Abstraction is the practice of temporarily forgetting details unnecessary to addressing the problem at hand. Defining and calling functions is another example of how computer scientists use abstraction to solve problems. Once you have written a function that you know works as intended, you can call the function as often as you wish, without worrying about the details or problems you had to solve to get it working.

IN CODE STUDIO, FIRST WATCH THIS VIDEO: Intro to Functions Tutorial TO LEARN ABOUT MAKING AND USING AND CALLING FUNCTIONS IN JAVASCRIPT (ABOUT 4 ½ MINUTES)

DO THE PROGRAMS IN CODE STUDIO, WATCHING THAT YOU MAKE 4 FUNCTIONS DO THE PROGRAMS IN CODE STUDIO, WATCHING THAT YOU MAKE 4 FUNCTIONS. MAKE FUNCTION NAMES THAT MAKE SENSE I WILL CHECK YOUR SCREEN AND YOUR CODE WHEN YOU FINISH. You have homework!

Assessing Your Programs – here’s what I am looking for: The program draws the diamond. The program defines four functions: right(), drawStep(), drawSide(), and drawDiamond(). The names are less important than the existence of four functions with this functionality. The program makes a single call to drawDiamond(). The program looks clean and organized.