WEEK: 12
Active: November 11th - November 17th
Work Due: November 18th @ 11:59PM

What are Functions

Functions are pieces of code that perform actions. What does that mean? Well, let’s think about the two main functions we already use.

    function setup()
    {

    }

    function draw()
    {

    }

Both setup and draw are functions that perform actions. The setup function is called only one time, and it calls createCanvas, which is also a function! The draw is also a function that is called continuously and allows us to make things appear in our browser.

How do we know they are functions?

    function setup()
    {

    }

Let’s look at the setup function. It’s easy to know what section is a function because it starts with the keyword function. Then it is followed by the name of the function, in this case, setup, and then the function name is always followed by () parentheses. Finally, the body of the function is surrounded by {} curly braces.

Does this look familiar? It should! It appears like if statement.

Click here for this section’s Video


Previous section:
Next section: