Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save evanmarkowitz/2d3fea744a074c60452a14a2b1e7bca1 to your computer and use it in GitHub Desktop.

Select an option

Save evanmarkowitz/2d3fea744a074c60452a14a2b1e7bca1 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 (75 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: It removes the requested amount of elemnents from the array and leaves the remainder. a = [1, 2, 3, 4, 5, 0] a.drop(3) #=> [4, 5, 0]
  • What did you Google to help you with this task, and how did you pick your results? https://apidock.com/ruby/Array/drop gave me another example of the method drop works.
  • In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer: An array push adds a element to an existing array. arr = [6, 7, 8,] arr.push(9) #=> [6, 7, 8, 9,]
  • What did you Google to help you with this task, and how did you pick your results? I googled "Array Push Ruby" . I was able to learn correct purposes for Array#<< and Array#push and get a better context on when this would be used.
  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: It cuts the string into multiple strings to make an array.require 'pp'

words_str = 'Foo,Bar,Baz' words_arr = words_str.split(',') pp words_arr # ["Foo", "Bar", "Baz"]

  • What did you Google to help you with this task, and how did you pick your results? I googled "Ruby String Split". I used the CodeMaven result since the subtext seemed revelant to the question. It provided me with a better example than the original source.

  • 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 allows you to specify the elements in the Array you would like to select by creating a start and end based on their order. var vegetables = ['cucumber', 'tomato', 'lettuce', 'beets', 'asparagus']; console.log(animals.slice(2, 4)); // expected output: Array ["lettuce", "beets"]

  • What did you Google to help you with this task, and how did you pick your results? I was able to use the ruby-lang.org site to confirm my understanding of the language. I used it because it is the official API doc.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: The Javascript Object Values lists out the attributes of the object in an Array. const hotel = { Name: 'Marriot', Rooms: 42, };

console.log(Object.values(hotel));

  • What did you Google to help you with this task, and how did you pick your results? I googled "Object.values()". I used w3schools because it was recommended as a source for simple inquiries and it gave a concies answer.

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: Monopoly

  • 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: var streetName: ["St Charles Place", "Kentucky Ave"]
  2. Integer and/or float data: var price: [45, 60, 70,]
  3. Boolean data: var passGo: true var railroad: true
  4. Array data: var position: [2, 4, 7, 10,]
  5. Hash or Object data: var stCharlesPlace = { name: "St Charles Place" price: 65, rent: 10, }

3. Iteration (30 min)

  • On a blank sheet of paper, create a diagram that shows how you understand iteration working. Be detailed and get creative! When you're done, take a photo of your diagram and post it in the Mod 0 channel on Slack. Your instructor(s) will provide feedback in a thread. (If you're feeling extra fancy, feel free to create your diagram using software instead of pencil and paper)

  • 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.

  • Tie Shoes: Multiple steps need to be followed in a specific order, it is finished when the shoe is tied.

  • Call Students name from a list: Each name is called, then the task moves on to the next person, it is finished when the last person is called.

  • Make cake batter: Add each ingredient on the list until all the ingredients are in the bowl.

  • 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.

  • Check the stock items: You need to go in to each item check the stock, then move to the next item.

  • Present a string on a web page based on a boolean: If true, tell the customer that the item is in stock.

  • Find a name that matches off a list. Check each name and determine whether it matches, move on to the next one.

4. 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:

@katiescruggs
Copy link

Nice use of console.log for JavaScript testing. For your string and number examples in Monopoly, you actually used an array of strings/numbers instead of an actual string/number data type, but I think the data types are clear to you.

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