Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Trond240/ddf40eb8492fa28c56221eba4a9ba9c8 to your computer and use it in GitHub Desktop.
Save Trond240/ddf40eb8492fa28c56221eba4a9ba9c8 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: A ruby array drop is the process of droping elements from an array. For example a=[11,15,22,3,5,25] if I wanted to drop all elements besides index spots 2 and anything after 4 I would use a.drop(2,4) that would give us a new array #=> [22,3,5].

  • What did you Google to help you with this task, and how did you pick your results? I googled what is the Ruby array drop method. I remeber talikng about stackoverflow, I lokked for the top anser. I aslo found a couple more sites and compared the information.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: The ruby string split method is the process of dividing a string into an array of characters. For example our string would be "Good Morning" if we wanted to split thaty we would use "Good Morning".split this would seprate the string into a new array ["Good", "Morning"].

  • What did you Google to help you with this task, and how did you pick your results? I googled define ruby string split method, and also how to use the ruby string split mthod. I found a couple diffrent sites, my main choice was stackoverflow. I compared the information and went with the most up to date.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: The slice method is the process of cloning and returning selected array elements into a new array object. For example we would have our array : [10,11,98,22,14] if we were to slice() it would be cloned into the same array unless we give slice(2) which would give us a new array [98,22,14]. The array would start with 98 because we are telling the computer to begin at the 2nd number of the array.

  • What did you Google to help you with this task, and how did you pick your results? I google "how to do the javascript array slice method" and "define javascript method. I picked my results based on a couple of different sites and compared the information. By doing that I found free code camp which provided the best examples and explinations.

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: Captain Hook

  • 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: game name "captain hook" product category "board games"

  2. Integer and/or float data: number of players (int) 4 required age (int) 18

  3. Boolean data: In stock? true Are four players required? false

  4. Array data: List of character names ["Hook", "Kanye West", "Goku", "James Harden"] List of player pice colors ["Red", "blue", "Pink", "Orange"]

  5. Hash or Object data: store (key) and stock count for that store (value) {"Walmart": 200, "Target": 400, "Kmart": 30} media outlet (key) and review score for that media outlet (value) {"IGN": 8, "Game Pro": 9, "Fox Games", 6}

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.

  • stocking pizza boxes: Stocking pizza boxes would be a good example of a real life situation becuase for each box you would have to fold box into place and then place the box on the stack. This would be a loop that is repeated for each pizza box being folded.

  • clean reptile enclosure: Cleaning a reptile enclosure would be a good example of a real life sitiation because the process fopr each reptile enclosure is the same. Take the reptile out of the enclosure, clean the enclosure and place the reptile back repeating those steps for the next reptile.

  • taking fast food orders:Taking fast food orders would be a good example of a real life situation because for every customer you follow the same steps. You great the costumer, take the order, take payment, and provide the food. This process is repeated through out the day with each customer.

  • 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 miles per gallon: Calculating miles per gallon would be a good a example for a programming situation because we would have two mathematical steps to get our answer. Step 1 would be to get miles traveled from point a to b, step 2 would be to divide by your miles per gallon to get the answer. This process can be repeated for each trip.

  • Calculating tips: Calculationg tips would be a good example of a programming situtiation because we could use two mathematical steps to get the tip amount. Step 1 would be to get our bill total, step 2 would be to multiply the total by .20 to get %20 of the toatl bill. Those steps can be repeated for each bill total.

  • Organizing clothing catalog by brand: Organizing a clothing catolog by brand would be a good example of a programming situation because we would have a two step proocess by pulling the brand name and placing that item into its category. This process can be repeated for each of the different brand names.

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... #(student)"
.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;
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)
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... { |a,b| b == 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... def intialize(data)

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:

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