WEEK: 12
Active: November 2nd - November 8th
Work Due: November 9th @ 11:59PM

Types of functions

Besides having built-in functions and user-defined functions, there are functions with and without parameters. They look differently when they are defined and called. What do they look like?

Functions without Parameters

Recall that functions are created to combine multiple lines of code into one. The function below creates both a circle and a square. When the function CircleSquare is called, a single circle and square are drawn to the screen in a specific location.

    function CircleSquare()
    {
        circle(100,200,25);
        square(250,350,50);
    }

Functions with Parameters

In the previous example, the circle and square are drawn in only one location. However, we can send in parameters to change the location of the circle and the square.

Parameters are variables that are passed into the function.

    function CircleSquare(circleX, circleY, diameter, squareX, squareY, sideLength)
    {
        circle(circleX, circleY, diameter);
        square(squareX, squareY, sideLength);
    }

In the next section, let’s look closer at why programmers create functions.


Previous section:
Next section: