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.
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 drops a certain elements from the array and creates a new array without the droped elements. x = [2,4,6,8] x.drop(2) => [4,6,8]
- What did you Google to help you with this task, and how did you pick your results? Ruby array drop method. I chose ruby-doc.org.
- 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 moves a certain element to the end of the array and returns the array in its new order. x = ["a","b","c"] x.push("a") => ["b","c","a"]
- What did you Google to help you with this task, and how did you pick your results? I googled ruby array push method. I chose the same site that I used on the first question.
- 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 in Ruby splits a string into sections along a predefined string or regex and returns an array of smaller strings. "hello world".split => ["hello", "world"]
- What did you Google to help you with this task, and how did you pick your results? I googled ruby string split method. I used the same site but I also checked another site to help me come up with a better definition.
- 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 select an element in the array and return it as a new object. It doesnt change the original array. var num = [2,4,3,5]; var even = num.slice(0,1); => even = [2,4]
- What did you Google to help you with this task, and how did you pick your results? I googled javascript array slice. I chose w3schools.com becasue it seems reliable and has good examples.
- 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 object.values method outputs the individual values of each element in an array. const x = { a: 'Sam', b: 23}; console.log(Object.values(x)); => ['Sam',23]
- What did you Google to help you with this task, and how did you pick your results? I googled javascript object values method. I chose the first site because it had a good definition and I recall it being one of the trustworthy sites that I wrote down.
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.
- String data:"names of properties","names of characters"
- Integer and/or float data: prices of properties, prices of tax, prices of hotels
- Boolean data: did someone land on your property, did someone land on chance, did someone land on an unowned property
- Array data: [list of properties owned by player], [list of properties in one region]
- Hash or Object data:[player: amount of money owned], [property: amount of hotels or houses]
-
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 game of football. Until the offense scores or turns the ball over, keep calling and running plays. The process is changed slightly but repeated until an outcome is met.
-
A game of golf. Until the ball is made in the cup, keep hitting the ball. The way you hit the ball changed with each shot but it is repeated until the outcome is met.
-
A crowded bar meeting its full capacity. Everytime a customer enters the bar the loop is repeated and the number increased by one until the max number is met.
-
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.
-
A program that asks a user for random number between one and one hundred until the user picks a number higher than fifty the program repeats and asks for another number.
-
A program that tracks the stock of a product in a store. Each time the product is purchased the loop repeats with the value decreasing by one until the value of the stock gets to a certain value and the loop will end and more product will be reordered.
-
A program for the game battleship that asks the user to guess a location on an array and also place a ship on another array. The loop will repeat and continue asking for loactions to be chosen until every spot the ship is in is guessed correctly. The loop will then stop and the battleship destroyed.
- 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\`$ "
If you have any questions, comments, or confusions from the any of the readings that you would an instructor to address, list them below:
Nice work, @SamuelColeman! For your iteration examples, make sure that you are starting with a collection / array to loop over. All of your examples are waiting until a condition is met, which would be a while loop instead of iteration.