Session 5 Conditional Logic, Iteration, and Assessment Expectations

Goals

By the end of this session, you will be able to:
  • understand how to break down programming problems using top down design
  • define iteration in programming
  • demonstrate iteration in real-world and programming situations
  • understand assessment expectations

Agenda

Materials

  • Notebook
  • Writing instrument
  • Laptop
  • Headphones & mic

Housekeeping and Goals

Wins

  • Great work asking questions in the public channel!
  • Answering questions in the public channel is the best way to solidify your learning and practice communicating technically

Follow-Ups

  • Make sure that you’re working on your capstone
    • try to get as far as you can
    • you’ll be much better prepared on day 1 of mod 1 if coding becomes a daily habit
    • have you been practicing your keyboard shortcuts?
  • We will add answers to the section from last session that asks you to tell us what’s wrong with ‘x’. That’s a great suggestion.
  • Reload this page

Intros, Review, and Icebreaker

Intros, Review, and Icebreaker

Person with the shortest first name goes first.

1. Introduce yourself: name, pronouns

2. What is a book, tv show, or movie that you've read/watched recently and really enjoyed? Why?

3. Accountability review: what tangible progress have you made toward the focus skills you identified at the beginning of Mod 0?

Have extra time? Share what extra things you're doing to get ready to start school at Turing.

Mock Assessment Follow-up

This is a great time to ask to get clarity on expectations or even some feedback on your responses.

The most common issues we run into that leave people pending on the assessment are as follows:

  • method definitions are too broad and don’t actually change an attribute or create a return value.
  • values aren’t filled in properly, using proper syntax for a particular data type
  • format of the top down design portion is wildly off. Only use markdown if you’re really comfortable

Top down design… continued

Conditional Logic is something we use often when solving problems in programming. The same problem may require some additional steps given a certain input or context. It typically manifests itself in code with if statements checking against a boolean value.

Let’s go back to our pizza example from session 4. In that example we assumed that we had all of the necessary ingredients to make our delicious pie. But what if, we didn’t?

Making Pizza

1 Prepare Dough
  1.1 acquire dough
    If there's dough in the fridge?
      1.1.1 grab dough from the fridge
      1.1.2 walk dough to counter
    if there's not
      1.1.1 go to store
      1.1.2 find prepared pizza dough
      1.1.3 purchase prepared pizza dough
      1.1.4 return home
      1.1.5 walk dough to counter
  1.2 place dough on pizza stone
2 Add Sauce
4 Add Toppings

Top down design in programming

Thus far, we’ve only been applying these scenarios to problems we encounter in everyday life. Let’s apply that same process to building software.

Let’s say for instance, that we are building a file uploader. The uploader will either let the user know that their file has been uploaded successfully or provide an error message to the user if it was not. The two constraints that prevent a successful download are that the file must be smaller than 1gb and a that it must be in either markdown or text format.

Let’s break it down:

File uploader

1 Recieve file 
2 Perform validation checks
3 Output message

Some problem solving tips:

  1. Always make sure that you understand the problem
    • Read through it a few times
    • Can you explain it layman’s terms?
    • If not, ask for clarification. Applies at Turing, in interviews, on the job.
  2. Start with a simple use case
    • See if you’re able to get the simplest implementation at first
    • Add complexity later
    • Take the example above, what happens if we don’t worry about the error cases to begin with?

Try It (Break Out Rooms): Top Down Design (~15 minutes)

Using top down design, write out a login form for a website. The form has two inputs and a submit button. One input to enter their email, and another input to enter their password.

In order to submit the form, the email must be valid and their password must be longer than 8 characters.

The user should see an error message if they are unable to submit the form

check out airbnb's email login for clarity


Iteration

Iteration (or looping for a specified number of times) is a process of repeating a task for each object in a collection. For each of the scenarios below, we’ll walk through using props to demonstrate the concept.

Iteration in Real Life

These are examples that would be programatically challenging because they would require a ton of steps, but are things that we do everyday.

Scenario Collection For each... Do this: Then:
Grading papers papers paper
  1. read through it
  2. mark the score on the top
repeat with next paper
Feeding animals animals animal
  1. bring the animal to the food bucket
  2. allow the animal to eat
  3. bring animal back to barn
repeat with next animal

Iteration in Programming

By “in programming”, we mean things that could be done, with relative ease, by a computer. Like crunching numbers.

Scenario Collection For each... Do this: Then:
Calculating max heart rate birth years year
  1. subtract birth year from 2019 to get age
  2. subtract age from 220
repeat with next year
Formatting names names name
  1. capitalize the first letter
  2. lowercase all remaining letters
repeat with next name

Try It: Iteration in Real Life and Programming

Brainstorm a real life scenario that uses iteration. Fill out the table below and be ready to share.

Scenario Collection For each... Do this: Then:

Think back to your grocery store app. What is something you said you'd keep inside of an array? Why might you need to iterate over that collection? Jot down your scenario below.

Scenario Collection For each... Do this: Then:

Iteration Syntax

We’ll go into breakout rooms to briefly discuss the syntax for iterating in Ruby and JavaScript.

Are you a or student?

Mod 0 Technical Assessment

This is our final Mod 0 technical session. Your assignment between now and Thursday is to find 80 minutes to complete the Mod 0 Technical Assessment.

SAMPLE INSTRUCTIONS

This work portion assessment should take you approximately 70 minutes, but we recommend taking an additional 10 minutes to throughly read over the expectations outlined in this document. The timed nature is meant to get you used to working under pressure.

First, fork the assessment checklist. You will use this checklist to ensure that you have met the Mod 0 Technical Assessment expectations.

Part I: Creating Directories and Files; Initializing Git and Pushing to GitHub (10 min)

  1. Use your terminal to create a directory called ...
  2. Inside of that directory, make an empty text file called ...
  3. Initialize your directory as a git repository.
  4. Add your file and commit using the message "Initial commit"
  5. Create a public repo on Github with the same name.
  6. Add the remote and push your local repository to Github.

Part II: Top Down Design (25 min)

  1. Open up your ... file in your text editor.
  2. Break down the process of ... (We will leave the situation intentionally vague so that you can choose what angle you feel most comfortable with. Although we are not looking for a specific "answer" for how you break this down, you should be as detailed as possible. It is better to break things down too much than to oversimplify a process. Use the same process and notation that we used during Session 5 with a dash mark and one indent for every new layer.)
  3. Save your file.
  4. Add and commit your changes.
  5. Push your changes to Github.

Part III: Classes, Objects, Attributes, and Methods (35 min)

  1. Inside of ..., create a new directory called ...
  2. Inside of ..., create four files: ..., ..., ..., and ...(If you're comfortable trying markdown at this point, feel free to use .md instead of .txt).
  3. Open up ... in your text editor.
  4. Brainstorm one class that might exist in a ... and put this at the top of the file.
  5. List at least four attributes for that class. In parentheses, list the data type for that attribute (string, boolean, integer, float, hash/object, datetime).
  6. List at least four methods for that class. In parentheses, explain what the method does, including the names of the attributes that it uses or modifies.
  7. Save your file.
  8. Add and commit your changes for this class.
  9. Open up ... in your text editor.
  10. At the top, type the name of an object that is an instance of your class.
  11. List the values for each attribute.
  12. List the results of the method being called for this specific object.
  13. Save your file.
  14. Add and commit your changes for this class.
  15. Repeat steps 3-8 with ...
  16. Repeat steps 9-14 with ...
  17. Push your changes to GitHub.

Done?

Check off all of the items on your forked checklist, then send the checklist to Tim and David in a DM on Slack.