# 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. - [x] In your own words, what does the Ruby array [drop](https://ruby-doc.org/core-2.4.0/Array.html#method-i-drop) method do? As you're explaining, be sure to provide an example. Your answer: The drop method will remove the amount of elements you decide from the beginning of an array. - [x] What did you Google to help you with this task, and how did you pick your results? ruby documentation array methods - [x] In your own words, what does the Ruby array [push](https://ruby-doc.org/core-2.4.0/Array.html#method-i-push) method do? As you're explaining, be sure to provide an example. Your answer: The push method will push an element to the end of an array. For example if you have the array vowels = [ "A", "E", "I"] and do vowels.push("O").push("U") you should get vowels = [ "A", "E", "I", "O", "U"] - [x] What did you Google to help you with this task, and how did you pick your results? I searched "ruby documentation push method" without the quotes, and decided to use ruby's actual documentation page as it should have up to date information. - [x] In your own words, what does the Ruby string [split](https://ruby-doc.org/core-2.4.0/String.html#method-i-split) method do? As you're explaining, be sure to provide an example. Your answer: The split method will split up a string into individual strings based on a space. For example. "I love to eat tacos".split will yield you ["I", "love", "to", "eat", "tacos"] - [x] What did you Google to help you with this task, and how did you pick your results? I didn't google this time as I already had up Ruby's documentation page and just looked up #split within it. - [x] In your own words, what does the JavaScript array [slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) method do? As you're explaining, be sure to provide an example. Your answer: Slice seems to remove a number of elements within an array from the beginning. If you have an array days = ["Monday", "Tuesday", Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] and do console.log(days.slice(3)) your expected output should be days = ["Thursday", "Friday", "Saturday", "Sunday"] - [x] What did you Google to help you with this task, and how did you pick your results? I searched "JavaScript array slice method" without the quotes and decided to use Mozillas page as it was mentioned in session 2. - [x] In your own words, what does the JavaScript object [values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values) method do? As you're explaining, be sure to provide an example. Your answer: Values method will output an objects values in an array for you to see. Example: const pizzaSize = { personal: "8in" small: "12in" medium: "16in" large: "20in" } console.log(Object.values(pizzaSize)); //Your output will be: Array ["8in", "12in", 16in", "20in"] - [ ] What did you Google to help you with this task, and how did you pick your results? I searched "JavaScript object values method" and found the Mozilla documentation page mentioned in session two. ### 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: Battleship - [ ] 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: "Hit", "Miss" 1. Integer and/or float data: Life = 100, Damage = 0 1. Boolean data: Your turn? True/False, Were you hit? True/False 1. Array data: Your position on the board = [A0, B0], Your fleet = ["carrier", "battleship", "cruiser", "submarie", "destroyer"] 1. Hash or Object data: Fleet = { "carrier": 5, "battleship": 4, "cruiser": 3, "submarine": 3, "destroyer": 2 } ### 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. - Checking out library materials. You repeat the same task of scanning an item until all your items are checked out to you. It's a repeated process - Graded assignments that you want in order from least to greatest. You check each grade to the next and place them in their proper order. - Shopping online. When you have a cart with items and are ready to checkout the cart will iterate through each items price to give you a total. - [ ] 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. - - - ### 4. Modify your Bash Profile (10 min) - [ ] Watch [this video](https://drive.google.com/file/d/1s_CDBnxHSA0HDWldjosulthAvBi-C-d5/view?usp=sharing) 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.