WhatILearnedInWeek2

Return of the Functions

  • Functions

  • Functions with Parameters

  • Functions with Indices

  • Functions with Global Variables

  • Functions with Returns

Booleans

  • What are they?

  • If and Else

Functions what are they and how do we use them?

Alt Text

Generally speaking, a function is a "subprogram" that can be called by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the function body. Values can be passed to a function, and the function will return a value.

Functions with Parameters:

  • Functions can return values that can be displayed, assigned to variables, or passed to other functions.
  • These functions represent values outside of the local scope or outside the Functions.
  • Functions with Global Variables are similar to Functions with parameters as they are outside the local scope and reside in the global scope.
  • Once we got comfortable with calling functions with global parameters we moved onto Functions with Returns.
  • Functions with returns is a way of calling your own function within the function. Whatever is immediately after return becomes the output of our function.
  • What happens in functions stays in functions. Inside a function, you can look at the code outside.The code inside is in impenetrable black box that can be viewed but never peek inside. Alt Text
  • Once we learned how to return functions we were now able to pass in parameters and move into more complex string such as indices. Which allowed us to pick out specific character values within the string.

Booleans

  • Very often, in programming, you will need a data type that can only have one of two values, like (True or False).
  • This is important when creating a website as it allows the application to show the right page.
  • Although they sound simple they can be very complex when several factors come into play.
  • Which leads us to if-and-else. These are key in determining what step of the process a user may be. Have they logged? If logged-in show user page, if not, show sign-up page. If logged in what page should we show them? Free user page or member page? Alt Text