← All lessons/Functions· Lesson 19 of 32

Parameters: giving a function inputs

Add parameters so one function can do its job at different positions, then call it with different arguments.

About 7 min

Functions can take inputs

A function is far more useful when it can take inputs. The names inside the parentheses of a definition are called parameters — they're placeholders for values you'll supply when you call it.

function drawFlower(x, y) {
  fill(255, 100, 150);
  ellipse(x, y, 40, 40);
}
x and y are parameters; they stand in for real numbers.

Now drawFlower(80, 120) draws a flower at (80, 120), and drawFlower(300, 250) draws *another* at (300, 250) — same recipe, different spots. The values you pass in (80, 120) are called arguments.

One function, called three times with different arguments.

NOTE

Parameters are the names in the definition (x, y). Arguments are the actual values you pass when calling (120, 120). Same idea, two words.

Your turn

Define drawFlower(x, y) that draws a flower (use ellipse with x and y). Then call it at least 3 times with different x and y values to scatter flowers around the canvas.

Hints