Learn

Programs can get long and complicated. Our code may start simple but grow into thousands of lines, often using the same commands over and over. When we write that much code, we make more mistakes and create bugs.

When we find repetitive code, we should consider moving it into functions. Functions are a named group of multiple commands that can make our code shorter and easier to read. Once we’ve defined a function, we can use one line to repeat that block of code.

Let’s get started with functions.

Instructions

Move Left and other commands are functions themselves. Each time we place the command, it handles all of the logic behind the scenes to move Codey around.

To solve this exercise, move Codey to the goal.

Hint
Codey will need to go down and to the right.
Solution
Move Right Move Right Move Right Move Down

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?