A Product Manager Learns to Code: Week 6

This was a big week. I finished up a huge chapter on loops, and started in on functions. I’m still working on functions.

Functions are a game changer. I’m started to understand that functions are perhaps the most important thing to learn in programming. Functions are written once and then reused over and over again throughout a piece of code.

This is totally how I code - chillin' with my bike.

This is totally how I code - chillin' with my bike.

Advice of the week: When you’re learning core concepts, it’s really hard, and you should dedicate time every day, even if it's just 15 minutes. Make a small dent every day, rather than trying to study for 8 straight hours on the weekend. Let things soak in.

Accomplishments for Week 6: 

  • I wrote my first nested loop. I definitely talked about this at length with my entire dev team at work, which is extremely embarrassing, because they do way more complicated stuff for a living. (For the record, they were nice about it, and encouraging.)
  • I wrote my first function. Again, this was an extremely simple function (and Udacity definitely gives you clues for how they want you to write it) but it felt like a big accomplishment.
A (very) simple function.

A (very) simple function.


  • Functions get confusing because you have to keep in mind there are arguments and parameters. A parameter is always going to be a variable (declared in the function declaration), and an argument is an actual value.
  • Loops often exists as part of functions. This was confusing for me at first, because you’re declaring parameters as part of the function, but then you’re declaring other variables inside of the loop. It’s hard to keep all of the variables straight. 
  • Just when I thought I was comfortable with functions, I was taught that you can store a return value in a variable, and use that variable to do other stuff. Jesssuuussss my head hurts. 
    • A function's return value can be stored in a variable or reused throughout your program as a function argument. 


Ah Ha Moment(s): 

  1. Understanding the difference between print (console.log) and return. Printing and returning are two different things. Duh.
  2. A function ENDS at return. So if you have: 

    Function declaration
    Function body
    return x
    return y

    the function will return x, because the function ended when you wrote 'return' the first time. Therefore, the function never gets to the ‘return y’ part.