Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save EllieJellyBean/eead3339d3b65c5b0f6688850e7548ab to your computer and use it in GitHub Desktop.

Select an option

Save EllieJellyBean/eead3339d3b65c5b0f6688850e7548ab to your computer and use it in GitHub Desktop.

Session 2 Practice Tasks

The assignments listed here should take you approximately 55 total minutes.

CAREFULLY READ ALL THE INSTRUCTIONS BEFORE STARTING THESE EXERCISES!

To start this assignment:

  1. Click the button in the upper right-hand corner that says Fork. This is now your copy of the document.
  2. Click the Edit button when you're ready to start adding your answers.
  3. 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. Creating Files and Directories (10 min)

Need help? You can go back to the files/directories portion of the lesson here.

Scroll down to the bottom of this page and look at the image of the directories and files. Use commands in your terminal to create the directories and files structured exactly how they appear in the image.

When you're done, type history to see your commands. Copy and paste the commands that were used to create the directory and files:

elliemiller@Ellies-MacBook-Pro session_3_practice % history
   28  cd session_3_practice
   29  mkdir essays
   30  cd essays
   31  touch life_lessons.docx
   32  touch notes.docx
   33  ls
   34  mkdir book_projects
   35  cd book_projects
   36  touch library_analysis.docx
   37  touch book_report.docx
   38  cd session_3_practice
   39  cd ..
   40  cd ..
   41  pwd
   42  ls

Since this is just a practice directory, feel free to remove the parent directory session_3_practice when you're done with this exercise.

2. Git Practice (15 min)

Follow the steps below to practice the git workflow. Be ready to copy-paste your terminal output as confirmation of your practice.

  1. Create a directory called git_homework. Inside of there, create a file called quotes.txt.
  2. Initialize the directory
  3. Use git status to ensure you are set up for tracking using Git
  4. Add your quotes.txt file to the staging area
  5. Check the git status
  6. Create an initial commit (Note: Be sure to follow the correct message format for your first commit!)
  7. Check the git status
  8. Add your favorite quote to the quotes.txt file
  9. Check the git status
  10. Check the changes you've made using git diff
  11. Add the changes to the staging area
  12. Commit the new changes (Note: Be sure to follow convention for commit messages!)
  13. Check the status
  14. Show the log of your work in oneline format using git log (This will likely require some Googling)

Copy and paste all of the terminal text from this process below (not just the history):

elliemiller@Ellies-MacBook-Pro ~ % mkdir git_homework
elliemiller@Ellies-MacBook-Pro ~ % la
zsh: command not found: la
elliemiller@Ellies-MacBook-Pro ~ % ls
Applications	Downloads	Music		Tufts Info.txt
Desktop		Library		Pictures	git_homework
Documents	Movies		Public
elliemiller@Ellies-MacBook-Pro ~ % cd git_homework
elliemiller@Ellies-MacBook-Pro git_homework % touch quotes.txt
elliemiller@Ellies-MacBook-Pro git_homework % ls
quotes.txt
elliemiller@Ellies-MacBook-Pro git_homework % git init             
Initialized empty Git repository in /Users/elliemiller/git_homework/.git/
elliemiller@Ellies-MacBook-Pro git_homework % get status
zsh: command not found: get
elliemiller@Ellies-MacBook-Pro git_homework % git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	quotes.txt

nothing added to commit but untracked files present (use "git add" to track)
elliemiller@Ellies-MacBook-Pro git_homework % git add quotes.txt
elliemiller@Ellies-MacBook-Pro git_homework % git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   quotes.txt

elliemiller@Ellies-MacBook-Pro git_homework % git commit -m yay
[main (root-commit) 46bf3c2] yay
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 quotes.txt
elliemiller@Ellies-MacBook-Pro git_homework % git status
On branch main
nothing to commit, working tree clean
elliemiller@Ellies-MacBook-Pro git_homework % git diff quotes.txt
elliemiller@Ellies-MacBook-Pro git_homework % atom   
elliemiller@Ellies-MacBook-Pro git_homework % git add quotes.txt
elliemiller@Ellies-MacBook-Pro git_homework % git status
On branch main
nothing to commit, working tree clean
elliemiller@Ellies-MacBook-Pro git_homework % git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   quotes.txt

no changes added to commit (use "git add" and/or "git commit -a")
elliemiller@Ellies-MacBook-Pro git_homework % git diff quotes.txt
diff --git a/quotes.txt b/quotes.txt
index e69de29..99050cd 100644
--- a/quotes.txt
+++ b/quotes.txt
@@ -0,0 +1 @@
+"Understanding does not always lead to fluency, and simply having an eager imagination does not always pass as a shortcut for putting in the hard work."
elliemiller@Ellies-MacBook-Pro git_homework % git add quotes.txt
elliemiller@Ellies-MacBook-Pro git_homework % git commit           
[main de7ebbb] second
 1 file changed, 1 insertion(+)
elliemiller@Ellies-MacBook-Pro git_homework % git status
On branch main
nothing to commit, working tree clean
elliemiller@Ellies-MacBook-Pro git_homework % git log --pretty=oneline
de7ebbbabe77a254264369ee102ea18fafae5df9 (HEAD -> main) second
46bf3c22bd67cf1fbfae249cc5dcd17d0945f8aa yay
elliemiller@Ellies-MacBook-Pro git_homework % 

IMPORTANT: Do NOT remove this git_homework directory. You will be using this directory during the next session.

3. Classes, Attributes, and Methods (15 min)

Look at the template below for a ConvenienceStore class. Fill in missing blanks with additional attributes and methods.

Class: ConvenienceStore

Attributes:
- totalSales (integer)
- numberOfCustomers (integer)
- address (string)
- phoneNumber (string)
- isOpen (boolean)
- clockedIn (boolean)
- candyInventory (array)
- candyPrices (array) **EXTENSION**

Methods:
- closeStore (updates the isOpen attribute to false)
- updateTotalSales (updates the numberOfCustomers attribute with new sales data)
- updateNumberOfCustomers (updates the totalSales attribute with new sales data)
- clockedOut (updates the clockedIn attribute to false)
- updateEmployeeHours (updates employee's total hours for the pay period)

4. Modify your Zsh Prompt (10 min)

  • Make sure that your shell is set to zsh by running the following command: $ chsh -s /bin/zsh. Remember to omit the $! Note that macOS Catalina and later operating systems already use zsh as the default shell.

  • Watch this video and follow each step to modify your own zshrc configuration file. As mentioned in the video, you will need this snippet below:

# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }

# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '%b'

# Determine if current working directory is a git repository
git_branch_color() {
  if current_git_status=$(git status 2> /dev/null); then
    parse_git_dirty
  else
    echo ""
  fi
}

# Change branch color if working tree is clean
parse_git_dirty() {
  if current_git_status=$(git status | grep 'Changes to be committed:\|Untracked files:\|modified:|deleted:' 2> /dev/null); then
    echo "%F{red}"
  else
    echo "%F{green}"
  fi
}

# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%F{white}%d $(git_branch_color)${vcs_info_msg_0_} %f$'

5. Self Assess

Using the rubric below, assess how you did with these exercises. These are the same metrics your instructors will use to determine if you are prepared for Mod 1!

  • I read carefully read ALL directions
  • I completed all parts of the exercises (not including Extensions) to the best of my ability
  • I used correct syntax, spacing and naming conventions
  • I followed ALL formatting instructions
  • I pushed myself out of my comfort zone and experimented/broke things to try to learn
  • I spent no longer than 20-30 mins Googling a specific problem before asking for help
  • I went back to the lesson to search for clarification before asking for help

Stuck? Having Issues?

Are you stuck on something? Here is the BEST way to ask for help:

  • Find the Session 2 HW Thread in your Mod 0 Slack channel
  • Start or reply in the thread with the problem you are facing. Be sure to follow the guidelines for asking questions below:
    • I can explain what I am trying to do or accomplish
    • I can what I have tried so far and/or what resources I've tried online
    • I can describe specifically what I am stuck on
    • I provided screenshots and/or code examples to give context
      • If I provided short code examples, I used inline code formatting for single lines of code/error messages
      • If I provided larger blocks of code, I used a code snippet in the correct format (such as .js or .rb)
  • Usually, your classmates will be able to answer your question or point you in the right direction very quickly! If not, an instructor will reply within 24-48 hours

🦀 I completed the refactoring checklist! 🦀

Extensions

  1. This course is how I personally learned command line. If time permits, I highly recommend reading and practicing.

  2. Also recommended by Jeff Casimir: Michael Hartl's Learn Enough Command Line.

@francepack
Copy link

@EllieAzaveda
Overall, nice job here. Well done following instructions in part 2, but don't forget to put quotes around your git commit messages! They should appear like follows git commit "Commit message here". You will continue to get practice with git workflow as you do your prework.

In part 3, how can you make method clockedOut read more like the other methods? Remember- you want those names to start with active verbs in the most simple form. Another tip- methods that 'update' are fine, but a variety is always nice- try some methods that add, remove, or do more specific things than just update.

Let me know if you're able to make updates here or have questions about this feedback.

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