Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save lrs8810/f5ae63b1fe75a9d974941bb4f568d1d3 to your computer and use it in GitHub Desktop.

Select an option

Save lrs8810/f5ae63b1fe75a9d974941bb4f568d1d3 to your computer and use it in GitHub Desktop.
Mod 0 Session 2 Practice Tasks

Session 2 Practice Tasks

The assignments listed here should take you approximately 2 hours.

To start this assignment, click the button in the upper right-hand corner that says Fork. This is now your copy of the document. Click the Edit button when you're ready to start adding your answers. To save your work, click the green button in the bottom right-hand corner. You can always come back and re-edit your gist.

1. Documentation and Googling (60 min)

Documentation of a langauge, framework, or tool is the information that describes its functionality. For this part of the practice tasks, you're going to practice digging into documentation and other reference material.

NOTE: The linked documentation for each question below is a good starting place, but you should also be practicing your Googling skills and sifting through the results to find relevant and helpful sites.

  • In your own words, what does the Ruby array drop method do? As you're explaining, be sure to provide an example. Your answer: The drop method in Ruby will drop the first elements of the array defined by the method and return the rest of the elements. For example, if you have an array with 5 elements and use the drop method (3), then it will exclude or "drop" the first 3 elements and return the rest of the elements. a = ["element 1", "element 2", "element 3", "element 4", "element 5"] a.drop(3) #=>["element 4", "element 5"]

  • What did you Google to help you with this task, and how did you pick your results? I googled: Drop method of an array in Ruby. My second result was the link provided. I clicked on the first link and compared the information from there to the information provided. I also received results that were about the take method in Ruby. This lets me know I need to be more detailed in my searches, but that I can also learn from other similar methods.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: At the basic level, the split method will take a string and create an array of substrings based on either a delimiter which can be whitespace or something else. For example "My name is Laura" can be returned as ["My", "name", "is", "Laura"].

  • What did you Google to help you with this task, and how did you pick your results? I googled: Split method in Ruby. The same APIdock website came up in the Google results as the drop method question and I again compared the information to the Ruby-doc.org link provided, which matched. This lets me know that this is probably a good website to look up information for Ruby, but it will give me almost identical information to Ruby-doc.org so if I need more or different information I need to look at a different site.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: Simply put Javascript array slice method takes a part of an array and returns a new array. The array elements are numbered beginning with zero and a slice method does not include the last element. For example, if the var fruits = ['cherry', strawberry', 'kiwi', 'banana', 'mango'] and var favorite = fruits.slice(1, 3) the result would be strawberry and kiwi because cherry has a place of 0, strawberry has a place of 1, kiwi a place of 2, and banana a place of 3. The slice method does not include the end though, which is why banana was not included in the result.

  • What did you Google to help you with this task, and how did you pick your results? I am having a harder time with my Google Search for Javascript than Ruby and understanding the information presented. I did actually find success on W3 schools because it had a section where I could run code and once I did that and saw how the method worked, it clicked for me. I am not sure if this is the correct approach, but it was helpful for me.

2. Data Types (15 min)

Imagine that you're taking your favorite board game and turning it into a computer-based game.

  • Name of board game: PayDay

  • Use the space below to categorize game data into each of the following data types. You should have a minimum of two pieces of data for each category.

  1. String data: Player name: "Laura Schulz", Objective: "To become the Payday champion, you must have the most money after payday comes within the time frame (in months) previously chosen."
  2. Integer and/or float data: Number of spaces the player moves: 3, Amount collected when passing PayDay square in dollars: 3500, Suggested player age: 8
  3. Boolean data: Is it the player's turn? true, Did the player pass PayDay square? false, Does player A need to pay player B? false
  4. Array data: List of spaces ["Groceries", "Home Repairs", "Surprise Bonus", "Pay Day"], List of cards ["Mail Card", "Deal Card", "Lottery Card", "Event Card"]
  5. Hash or Object data: Card type (key) and number of that card type in deck (value) {"Mail Card": 54, "Deal Card": 36, "Lottery Card": 6, "Event Card": 36}, Color of money (key) and play monetary value (value) {"Orange": 100, "Yellow": 500, "Green": 1000, "Blue": 5000, "Purple": 10000}

3. Iteration (30 min)

  • Create a list below of three real-life situations where iteration is used. For each situation, explain why it would be an example of iteration.

  • Scenario: Washing the dishes, Collection: Dishes, For each dish..., Do this 1. Pick up dish 2. Scrub dish 3. Rinse dish 4. Put dish on drying rack, Then repeat with next dish. You have to perform the same action of scrubbing, rinsing, and placing the dish in the same area to all dishes until you are done and have a clean kitchen.

  • Scenario:Flossing your teeth, Collection: Teeth, For each tooth..., Do this 1. Place floss around tooth 2.Floss up and down around tooth, Then repeat with the next tooth.
    Each tooth needs the same flossing motion applied to it until all your teeth have been flossed.

  • Scenario: Eating shelled pistachios, Collection: Pishatios, For each pistachio..., Do this 1.Open the shell with your hands 2. Eat pistachio 3. Discard shell, Then repeat with the next pistachio. Eating shelled pistachios requires that you remove the shell before consuming them so you are performing the same act over and over to enjoy this snack.

  • Create a list below of three programming situations where iteration would be used. For each situation, explain why it would be an example of iteration.

  • Calculating sales tax on an ecommerce website. The collection: purchases. For each purchase, the program would 1. multiply the sales tax percentage and 2. add the sales tax to the purchase for the total. This would repeat for each purchase or transaction.

  • Giving the county for a specific city listed in a form. The collection: cities. For each city, the program would 1. cross-reference the city to the correct county on a list and 2. return the correct county. This would repeat for each city entered into the program.

  • Calculating the age of someone based on their birth year. The collection: birth year. For each year, the program would calculate 1. Current year minus the date and 2. return the resulting age. This would repeat for each year entered into the program.

4. Identifying Mistakes (15 min)

The following code examples each contain a mistake. Describe the problem for each.

Original Mistakes Problem
students.each do |student|
  puts "Welcome, #{student}"
end
students.each do |student|
  puts "Welcome, #(student)"
end
The problem is there are parentheses arounds student instead of curly backets.
.main-content {
  font-size: 12px;
  border: 3px solid black;
  font-family: sans-serif;
}
.main-content {
  font-size: 12px;
  border: 3px solid black;
  font-family: sans serif;
}
The problem is sans serif is missing the dash between sans-serif.
log(2, (1022 * ((score - min(score) over ()) / ((max(score) over ()) - (min(score) over ()))) + 2)::numeric) log(2, (1022 * ((score - min(score) over ()) / ((min(score) over ()) - (min(score) over ()))) + 2)::numeric) The problem is min(score) was used instead of max(score).
arr.product(arr).reject { |a,b| a == b }.any? { |a,b| a + b == n } arr.product(arr).reject { |a,b| b == b }.any? { |a,b| a + b == n } The problem is b is used instead of a, where a == b.
class Cat
  attr_reader :color, :name
  def initialize(data)
    @name = data[:name]
    @color = data[:color]
  end
end
class Cat
  attr_reader :color, :name
  def intialize(data)
    @name = data[:name]
    @color = data[:color]
  end
end
The problem is initialize is spelled wrong with the second i missing.

5. Modify your Bash Profile (10 min)

  • Watch this video and follow each step to modify your own bash profile. As mentioned in the video, you will need this snippet below:
# get current branch in git repo
function parse_git_branch() {
  BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
  if [ ! "${BRANCH}" == "" ]
  then
    STAT=`parse_git_dirty`
    echo "[${BRANCH}${STAT}]"
  else
    echo ""
  fi
}

# get current status of git repo
function parse_git_dirty {
  status=`git status 2>&1 | tee`
  dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
  untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
  ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
  newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
  renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
  deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
  bits=''
  if [ "${renamed}" == "0" ]; then
    bits=">${bits}"
  fi
  if [ "${ahead}" == "0" ]; then
    bits="*${bits}"
  fi
  if [ "${newfile}" == "0" ]; then
    bits="+${bits}"
  fi
  if [ "${untracked}" == "0" ]; then
    bits="?${bits}"
  fi
  if [ "${deleted}" == "0" ]; then
    bits="x${bits}"
  fi
  if [ "${dirty}" == "0" ]; then
    bits="!${bits}"
  fi
  if [ ! "${bits}" == "" ]; then
    echo " ${bits}"
  else
    echo ""
  fi
}

export PS1="\u\w\`parse_git_branch\`$ "

5. Questions/Comments/Confusions

If you have any questions, comments, or confusions from the any of the readings that you would an instructor to address, list them below:

  1. For those in the backend program, what is the best way to learn Javascript syntax? Ruby is so intuitive, but I'm struggling with Javascript.
@damwhit
Copy link

damwhit commented Jul 3, 2019

@lrs8810 nice job on this!

Regarding your question above, I wouldn't recommend looking into javascript until mod 4 when it is taught. Or possibly mod 3 if you are hitting all base expectations and looking for an added challenge. It'll be much easier to learn the syntax of other languages once you have a really solid understanding of one.

@lrs8810
Copy link
Author

lrs8810 commented Jul 3, 2019

@damwhit Thank you! That makes sense about learning the syntax of other languages once I have a solid understanding of one.

In regards to being evaluated as "Turing-Ready", I know it will be the culmination of all of our assignments and technical assessment, but will you let us know in these comments if there is anything we need to work on along the way to be considered "Turing-Ready"?

@damwhit
Copy link

damwhit commented Jul 3, 2019

@lrs8810 yes, I will let folks know if there is anything that they need to fix or work on. Thus far, you're doing great. Keep up the good work 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment