Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kawilliams8/9304003c3692b8044f5acbe3a5f8df6d to your computer and use it in GitHub Desktop.
Save kawilliams8/9304003c3692b8044f5acbe3a5f8df6d 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: The drop method removes a specified number of items from the beginning of an array. [1,2,3] becomes [2,3].

What did you Google to help you with this task, and how did you pick your results? "what does drop method do ruby" The first result previewed almost the same text as the provided link.

  • In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example.

Your answer: The push method adds some new items at the end of an array. [1,2,3] becomes [1,2,3,4,5,6]

What did you Google to help you with this task, and how did you pick your results? "what does push method do ruby" This unsurprisingly brought up the same site as the first question, so I used it again.

  • 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 split method takes a set of characters and divides it into an array of strings. There are several options for various results. "banana pancakes".split becomes ["banana", "pancakes"]

What did you Google to help you with this task, and how did you pick your results? "what is split method ruby" Same site was result #1 -- still serving its purpose.

  • 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 selects items in an array and copies them to a new one. You give a starting and end point in the original; the end point is not copied.

var fruits = [apple, banana, grapes, kiwi, strawberry, mango] var lessFruits = fruits.slice[1,4]

lessFruits will have [banana, grapes, kiwi]

What did you Google to help you with this task, and how did you pick your results? 'what is slice method javascript' I used the Mozilla documentation because I've looked at it before and (sort of) understand the layout.

  • 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 values method returns an array that contains the enumerable properties of that object.

What did you Google to help you with this task, and how did you pick your results? "javascript object values do?" and 'object.values example' I started with the Mozilla documentation, then searched for a definition of 'enumerable' and read some examples. I think it separates the key and returns the values from the pairs. This one makes the most sense to me:

let user = { name: "John", age: 30 };

Object.values(user) = ["John", 30]

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

  • 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: A few characters are "Mrs. White", "Miss Scarlet", "Mrs. Peacock", "Colonel Mustard"
  2. Integer and/or float data: Number rolled on the dice, number of cards left in the deck
  3. Boolean data: Does the suggested combination of room/suspect/weapon match the three cards hidden in the envelope? True/False.
  4. Array data: User's guesses could be stored over time as [character, room, weapon]
  5. Hash or Object data:

var winner = { suspect: "Mrs. Peacock", room: "Kitchen", weapon: "knife" };

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! This should not be the simple table that we used during the lesson. When you're done, take a photo of your diagram and send it to Rachel and Tim on Slack. (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.

  • A cook is making spaghetti sauce. They add a dash of salt, then taste the sauce. More salt, another taste. They repeat both steps until they achieve a satisfactory level of salt, then stop. This is iteration because they repeat the steps until satisfaction is "true", then stop the loop.

  • A person is playing a pinball game. They get three balls for fifty cents. They must achieve a certain score to earn additional pinballs to continue play. If the don't earn that score, the game ends. This is iteration because a player has an opportunity to meet/exceed the required score, but if they don't, they don't get endless pinballs.

  • A person finds a new favorite song. They put in on repeat, listening over and over happily. Eventually they get bored of it and need to stop the song. This is interation because their contentment allows the song to keep going. As soon as they're no longer content, they end the loop.

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

  • Someone adds an item to an online shopping cart. The website searches for similar items, based on matching a database of pre-set characteristics on the first item. The site offers more items to the customer until it runs out of matching items. This is iteration because the site will automatically check for similar items until it runs out of matches, then stop the action of offering.

  • A simple game is designed to guess a user's age. It starts low and escalates one year per guess, depending on whether the user says the guess is correct or not. The game stops when the users says it has guessed correctly. This is iteration because the action of adding a year continues until the user stops it, by saying that the guess was "true".

  • A website is set up to offer free shipping on its products when you buy over $100. As the user adds items to their cart, the site checks to see if the total is at or over $100. When it is, the cost for shipping is removed. This is iteration because the site has to keep checking the total against $100. Once that level is achieved, the shipping doesn't change again (unless the user removes items).

@timomitchel
Copy link

Katie, thanks for taking the time to complete these tasks. Remember, for iteration we will always start with a collection and iterate on each element or item in that collection. So for your game example, we would want to start with a collection of users and then perform the tasks you described on each user. I like that you're starting your google searches by looking at documentation. This is something we do every day as developers, so it's a great habit to get into.

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