# 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](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: It removes the specified number of items from an array, starting from the beginning. Example Array [1,2,3,4,5] drop 1 returns [2,3,4,5] - [ ] What did you Google to help you with this task, and how did you pick your results? I read the official documentation. - [ ] 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: It breaks a string apart based on a choose character, phrase, or other delimiter. String example “I ran around the house” could be split by a space and it would return the string as: “I”, “ran”, “around”, “the”, “house” - [ ] What did you Google to help you with this task, and how did you pick your results? split string ruby I went through the first 4 results until I found a simple explanation and example - [ ] 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 returns a new array and does not edit/touch the original array from the specified position. [1, 2, 3, 4, 5] slice 1 > [2, 3, 4, 5] - [ ] What did you Google to help you with this task, and how did you pick your results? Read the documentation. ### 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: Risk - [ ] 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: "Country Names", "Piece Names" 1. Integer and/or float data: numberUnits = 7, players = 4, diceResults = 12 1. Boolean data: Has correct number of cards for a turn in correctCards = True, playerOneControlsAustrilia = True 1. Array data: var countriesHeld = ["Serbia","Russia","Cyrpus"], var countriesPlayer = [5,15,20,40] 1. Hash or Object data: Var Player = "Matt", var countriesHeld = ["Serbia","Russia","Cyrpus"] ### 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. - Making Perogies. If dough is available and filling available, fill dough, fold, place aside. - Packing Envelopes, if addressed envelopes left and invitations available. Place invite in envelope seal. Repeat. - Reading book, if pages left read next page. - [ ] 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. - Displaying names of players in a video game. You would go through the array of players and display them on the screen. - Playing through songs on a digital album until the end. Array of song, playing each one until there are none left. - Playing through episodes in a series on Netflix. Array of shows in a series playing until user breaks loop or there are not more episodes. ### 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... |
| .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... |
| 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... |
| 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... |
| 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... |