The purpose of this lab is to get you and your partner familiar with git
, specifically, how to:
- Fork a repository
git clone
down a remote repositorygit add
to stage andgit commit
to commit changesgit push
to push up committed changes from a local repo to a remote repogit pull
to pull down changes from a remote repo to a local repo- How to manage merge conflicts
Note: This lab demonstrates a workflow that does not follow best practices as it will likely create many merge conflicts. However, it is a great place to start to learn the foundations of working collaboratively on Git!
For this lab, you will engage in Paired Programming. This just means you are collaborating live with a programming partner! When pair programming, both partners are always looking at, and working off of the same screen! This creates two roles:
- The driver is the one typing on the computer.
- The navigator is watching and checking their code, make suggestions, and doing research to support the driver.
Each role is important and distinct and individuals may perform differently in each role so it is recommended that you frequently switch between driving and navigating.
Read these instructions in their entirety before beginning:
- You will work in groups to implement various JavaScript functions.
- One group member, Partner A, will fork this repository. Only one group member should fork the repo. Partner B does not need to fork anything.
- In the forked repository, Partner A needs to add Partner B as a collaborator. This means that both groups members will have read and write (edit) access to the forked repo. Partner A will share the URL for the repository with Partner B and Partner B should accept the invitation on GitHub (check your email if you don't see a button to do so on GitHub).
- Both partners should
git clone
the forked repo to theirdevelopment/unit-0
directory using SSH. - Partner A will drive first with Partner B being the navigator. Partner A will type out the first function while Partner B reviews their code. The navigator may also make suggestions for improvements. Stage, commit, and push the changes up to the
main
branch of the remote repo (make sure you are in the correct folder in the terminal). - Double check the remote repo on Github to ensure the latest commit was successfully pushed up.
- Then, it will be Partner B's turn to drive and Partner A will be the navigator. Partner B needs to
git pull
down the latest commit (make sure you are in the correct folder in the terminal). Once the the code for the first function has been pulled down, Partner B will type out the second function, then push their changes up. - Continue switching driver-navigator roles for every function, with Partner A typing out all the odd numbered questions and Partner B implementing the even numbers questions. Every time you push up a commit, your partner will need to pull down the changes to their local repo.
- Your group should be alternating commits like this example below:
- Once you reach the bonus problems, divide up the questions that you will each be working on. Instead of pair programming and alternating pushing and pulling, you will switch to parallel programming using branches. Read about the Git Branching and PR process and attempt to implement it for this lab! You will need to each create your own branch, submit PRs for your partner to review and merge, and then handle merging branches. You got this!
Running into problems? Make sure you have done the following:
You can check which remote repository you are connected to by running the following command from inside a Git directory:
git remote -v
This will print out the remote repository location that we are using to fetch
/pull
changes from and push
changes to. For example:
origin https://github.com/benspector-mls/git-js-pairing-lab.git (fetch)
origin https://github.com/benspector-mls/git-js-pairing-lab.git (push)
Both partners should have the same urls for both fetch
and push
.
You can always use git status
to see if you have done these things.
After completing a function, remember to stage, commit, and push your code! The commands might look like this:
git status
git add index.js
git commit -m "completed the fiveToOneHundred function"
git push
Each time your partner pushes a new function to the repository, make sure to use git pull
to download those changes!
If you git push
your code before pulling down your partner's code, you will likely cause a merge conflict. No fear — we're prepared for this.
You will likely be presented with three options for how you can configure your repository to handle git pull
merging (merge, rebase, fast-forward only).
For now, we recommend using the first option git config pull.rebase false
. To avoid running this command EVERY time you first encounter a merge conflict in a repo, run the following commands:
git config --global pull.rebase false
git pull
Then, resolve the conflicts by doing the following:
- In your code editor, determine which code you want to keep and delete the rest, including the conflict markers.
- Then, stage, commit, and push your updated files.
- Finally, make sure that your partner pulls down the new merge commit that you created.
Be sure to test your functions as you write them! You can invoke the functions after they have been implemented or use console.log
to print out their return value.
-
Write a function
fiveToOneHundred
that console logs all numbers from 5 to 100. -
Write a function
multiplesOfThree
that console logs all positive numbers to 100 that is a multiple of 3.
Multiples of 3 are:
3, 6, 9, 12, 15, ...
- Write a function
multiplesOfThreeOrFive
that console logs all positive numbers to 100 if that number is either a mulitple of 3 or a mutliple of 5.
3, 5, 6, 9, 10, 12, 15, ...
- Write a function
untilNum
that takes in an integer parameter and console logs all numbers from 1 to that number.
untilNum(5) //prints out numbers 1 through 5
untilNum(9) //prints out numbers 1 through 9
untilNum(42) //prints out numbers 1 through 42
- Write a function
multiply
that takes in two number parameters and returns their product.
multiply(2, 4) //returns 8
multiply(10, -5) //returns -50
multiply(3, 7.5) //returns 22.5
- Write a function
add
that takes in two number parameters and returns their sum. But if the two values are the same, return triple their sum!
add(2, 4) //returns 6
add(10, -5) //returns 5
add(3, 7.5) //returns 10.5
add(5, 5) //returns 30 because the sum of 5 + 5 = 10 and 30 is triple that
add(6, 6) //returns 36 because the sum of 6 + 6 = 12 and 36 is triple that
- Write a function
isNegative
that takes in a number parameter and returnstrue
is the number is a negative value andfalse
is the number is a positive value.
isNegative(3) //returns false
isNegative(-2) //returns true
isNegative(Math.PI) //returns false
- Write a function
triangleArea
that takes in the height and base of a triangle and returns the area of the triangle.
triangleArea(5, 7) //returns 17.5
triangleArea(6, 8) //returns 24
- Write a function
betweenTwentyAndFourty
that takes in a number parameter and checks whether a given integer is within 20 to 40. It returnstrue
if it is andfalse
if not.
betweenTwentyAndFourty(20) //return false
betweenTwentyAndFourty(21) //return true
betweenTwentyAndFourty(39) //return true
betweenTwentyAndFourty(40) //return false
- Write a function
largest
that takes in three number parameters and returns the largest of the values.
largest(4, 6, 8) //returns 8
largest(30, 22, 17) //returns 30
largest(41, 108, 86) //returns 108
Once you reach the bonus problems, divide up the questions that you will each be working on. Instead of pair programming and alternating pushing and pulling, you will switch to parallel programming using branches. Read about the Git Branching and PR process and attempt to implement it for this lab! You will need to each create your own branch, submit PRs for your partner to review and merge, and then handle merging branches. You got this!
-
Write a function
printTime
that prints out the current time in the formatHH:MM:ss
. Do not hard code the hour, minute, or seconds values. -
Write a function
isLeapYear
to determine whether a given year is a leap year in the Gregorian calendar.
isLeapYear(2000) //returns true
isLeapYear(1900) //returns false
isLeapYear(2020) //returns true
isLeapYear(1999) //returns false
- Write a function
getExtention
to get the extension of a filename.
getExtention("hello.txt") //returns ".txt"
getExtention("app.js") //returns ".js"
getExtention("README.md") //returns ".md"
-
Write a function
absoluteNineteen
to compute the absolute difference between a specified number and 19. Returns triple their absolute difference if the specified number is greater than 19. -
Write a function
switchLetters
that creates a new string from a given string changing the position of first and last characters.
switchLetters("anne") //return "enna"
switchLetters("hello world") //return "dello worlh"
switchLetters("a") //return "a"
switchLetters("") //return ""
- Write a function
changeString
to replace every character in a given string with the character following it in the alphabet/
changeString("abc") //return "bcd"
changeString("helloworld") //return "ifmmpxpsme"