Search lessons

Suggested searches

Browse

Functions

Goals

  • Learn how to create a function to reduce repeated code
  • Learn how to create a function with parameters
  • Learn how to effectively make code cleaner with functions

Tasks

  • Create a function that returns the sum of the two parameters
  • Create a function that swaps two elements of an array
    • The function should take in an array and the indices to swap
  • Remake your calculator program using functions
    • Create a function that takes in the two numbers and the operation, and return the result
    • Replace your existing code with calls to that function
  • Try to go back and remake other past programs using functions

Reference