CodeJavaScript + p5.js · ⌃ Space for hints
Draft saved locallyJavaScript · Spaces: 2
Live preview move your pointer inside
Mission 01 11 min
Reward+140 XP

Create and Call a Function

A custom function gives a group of statements a name. Define one with function name() { ... }, then run it by calling name();. For example: function wave() { circle(100, 100, 30); } creates the function, while wave(); runs it. In this mission, move the existing badge drawing commands into a new function instead of copying them.

Learn more

01
Your mission

Move the badge drawing commands into a new function named drawBadge, then call drawBadge() from draw() so the badge looks the same.

  • Create function drawBadge() { ... } containing the existing badge drawing statements.
  • Remove those badge drawing statements from draw().
  • Call drawBadge(); inside draw() after the background is drawn.
Mission complete Run sketch
Mission demoCreate and Call a Function

Finished result only — the answer code stays hidden.