p5 Basics
Functions and For Loops
Fix the Error
Conditionals
Wild Card
100

What is setup() used for?

It runs once at the beginning and sets up things like the canvas and starting values.

100

What is a custom function?

A user defined reusable block of code.

100

fill("red", 10);
rect(0,0,50,50);

fill() doesn’t take two separate argument types for a color name and transparency (text and number)

You need RGBA values or a single color with alpha, like fill(255,0,0,10).

100

What does a conditional statement let a program do?

Branching paths; take a decision based on a condition.

100

What does an event like mousePressed() do?

It runs code only when the user clicks. Events let your sketch react to actions.

200

r = random(255), b = random(255), g = random(255), a = random(255)
What does the background(r, g, b, a) command do?


background(r, g, b, a) fills the whole screen with a color made from those random red, green, blue, and alpha (opacity) values.




200

Why use a custom function?

To reuse code and reduce repetition.

200

circle(xPos, yPos);

circle() needs three arguments (xPos, yPos, diameter). Here it only has two


200

What Boolean result must an if statement receive to run its block?

True

200

What is the purpose of a parameter?

To pass data into a function.

300

Why does the draw() function repeat?

It refreshes the screen 60x a second, allowing animation and live updates.

300

How many parts are in a standard for loop header?

three

300

function setup() {
  createCanvas(400, 400);
  let xPos = width / 2; }

function draw() {
  background(220);
  ellipse(xPos, 200, 50);}

Make the variable global or move it under draw to be local....



300

 If an if condition is false and there is an else, which block runs?

The else block.

300

Why do we use comments?

To explain our thinking so future-us (or teammates) can understand the code faster.

400

Why do we use variables in p5?

To store values (like positions, sizes, or colors) that can change as the sketch runs.

400

What does the middle part of a for loop control?

When the loop stops.

400

for (let i = 0; i < 5; i--) {
    ellipse(50 + i * 60, 100, 30);
  }

infinte loop time...

The loop is moving in the wrong direction.

Change i-- to i++.

400

What is the difference between = and == in a conditional?


 = assigns a value, == compares values.

400

What happens when you forget a closing bracket }?

The code block never ends, so the computer gets confused and throws errors in places that don’t seem connected.

500

What is the difference between a variable’s name and its value?

A variable’s name is the label you use to refer to it in your program.

A variable’s value is the data currently stored inside it, which can change while the program runs.

500

In a nested loop, how many times does the inner loop run?

Once per outer loop iteration.

500

for (let i = 0; i < 5; i++) {
ellipse(20, 20, 50);}

Why is this not doing what a loop usually should?

The loop repeats, but it's drawing the same ellipse in the same spot every time.  A loop needs something (like xPos or yPos) that changes each cycle to make multiple shapes.

500

What must be true for a condition using && to pass?

Both conditions must be true.

500

Why do programmers test often instead of waiting until the end.

Small errors are easier to spot early. Waiting makes debugging messy because problems stack on top of each other.

M
e
n
u