Practice: Organizing Code

💡 This is your chance to put what you’ve learned into action.

Try solving these practice challenges to check that you understand the concepts.

The solutions to each challenge are available, and you can view a video of the solution below each challenge. Try to go through the whole challenge without using the solution.

If you can’t do the challenge without looking the solution, it means you don’t understand the material well enough yet.

Try the next practice challenges without looking at the solution. If you need more practice challenges, reach out on Discord.

Distance Traveled

In this exercise, you'll use a helper function to help measure how far a footballer has run over the course of a match.

distance-traveled

Random Story Generator

In this exercise, you'll write a story with blanks (like your Mad Libs story), but fill them in with random words instead of input from the user.

random-story-generator

Date Format

In this exercise, you'll practice with helper functions to format dates.

date-format

Refactor another project

Tidying up your old code is a good way to review what you've learned already, and to practice noticing opportunities to reorganize your code.

Using the tips and techniques you learned this week, go back and review code that you wrote for a previous week. What do you see about that code that you can improve?

  • Can you extract a helper function?
  • Can you rename a function or variable to be more meaningful?
  • Can you restructure the code to have less nesting?