Lab 8 - Prep - Creating Remote Repo and Cloning it, Warm Up Program(s)
Create Your Remote Repository
This will create a remote git repository on github.
- Go to your account home (github.com/username).
- Click on the Repositories tab.
- Click the green New button on the right side.
- Give your repository the name lab-08-if-while
- The repository should be public (the default).
- Click "Initialize this repository with a README".
- Click Create Repository.
- Refresh your main GitHub page and you should see the new repository.
Cloning your repository
This will clone the repository you just created on GitHub on your local machine.
- open terminal
- (if doesn’t already exist) create a folder that consists of your first initial and last name in your home directory
cd ~
mkdir myname
- use pwd to verify that you’re in the correct folder
- you should be in ~/myname/
- if you’re not, cd into it
- to prove that this is not yet a repository, list all files in your current directory
ls -al
- it should contain only your previous labs
- it should not contain any .git folders
- Make sure again that you're in the correct directory! (/Users/student/myname or ~/myname)
- Clone the GitHub repository you just created: lab-08-if-while
git clone https://github.com/your_username/lab-08-if-while.git
- The output should be:
Cloning into 'lab-08-if-while'...
remote: Counting ojects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
- Check to make sure you've linked to your remote repository:
- Change into your repository directory (lab-08-if-while).
- Use the git remote command.
cd lab-08-if-while
git remote -v
- You should see:
origin https://github.com/your_username/lab-08-if-while.git (fetch)
origin https://github.com/your_username/lab-08-if-while.git (push)
- configure your name and email for your commits
# in the directory of your repository
git config user.name "my first and last name"
git config user.email "my@email.address"
- finally, use git config again to see if this worked:
git config -l
- (use should see your name and email appear in the configuration)
Creating and Saving Changes Locally, Sending to Remote Repository
In this part of the lab, you will edit a text file in your local repository, and then you’ll send it to your remote repository.
- open terminal
- make sure you’re in your local repository folder for lab-08-if-while
- use pwd to do this
- you should be in ~/yourname/lab-08-if-while
- if you’re not in your lab folder, change your directory to it
- if this doesn’t exist yet… make sure you completed the beginning part of this lab
- use git status to show that there aren’t any changes yet
git status
- it should give the following output
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
- You will have a file called README.md in your lab-08 directory. Open it using SublimeText (see below…)
- Go to Applications → SublimeText (or use Command+Spacebar to activate spotlight search, then start typing Sublime)
- Once SublimeText is open, open the README.md file by going to File → Open
- Add the following to your file: "This is lab 08...more JavaScript conditionals."
- Save your file by going to File → Save (or command+s).
- Switch back to terminal
- Use git status to show that you’ve made changes
git status
- it should give the following output; notice that it contains README.md
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in the working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
- if we want to save this file in the repository, we have stage it (that is, mark it as something that we’re ready to save / commit)
git add --all
- to check that you’ve staged your commit, use git status again
git status
- it should output the following text (note that README.markdown moved from untracked to Changes to be committed)
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD ..." to unstage)
modified: README.md
- now we’re ready to commit (that is, save the file to the local repository); everything after the -m is the message that will be associated with the changes that you’ve made
git commit -m "edited the README file"
- the output of the command should be:
[master 5b24d27] edited the readme file
...etc
- check the status again
git status
- notice that there is nothing staged and no more changes!
# On branch master
nothing to commit, working directory clean
- to show the changes that you’ve saved so far, use git log
git log --color
- it should show you the following…
commit 5b24d2777a602908978916ca8fe9c8dd2ed6036b
Author: bree <bzuckerman@citytech.cuny.edu>
Date: Wed Mar 5 11:45:21 2015 -0500
edited the README file
- you can share your changes / send them to a remote repository by using git push
git push origin master
- it should result in:
Counting objects: 3, done.
Writing objects: 100% (3/3), 242 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bzuckerman/lab-08-if-while.git
* [new branch] master -> master
- go back to GitHub and look in your repository. You should see the changes in the Readme file.
Instructions for Warm-Up Programs
Note that ALL OF THESE FILES MUST BE SAVED IN THE LOCAL REPOSITORY THAT YOU CREATED FOR THIS LAB.
add dice
Write a program that asks for the result of two dice rolls. Add the results of both rolls and print out the sum.
- using SublimeText, create a new file called adddice.html in your repository directory: ~/Desktop/llorenzo/lab-08-if-while/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- the program should ask for the result of the first die roll: “Give me a number for the first roll (1-6)”
- the program should ask for the result of the second die roll: “Give me a number for the second roll (1-6)”
- use the parseInt function to convert both inputs from a string to a number (for example: num1 = parseInt(roll1, 10))
- then… add both numbers together and print out the output to the JavaScript console
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
(prompt) Give me a number for the first roll (1-6)
> 1
(prompt) Give me a number for the second roll (1-6)
> 5
The sum of both rolls is 6.
- save your file in SublimeText
- use git status, add, commit, and push to save your file in version control and submit it
fortune
Write a program that asks for number. The program will translate that number into a fortune.
- using SublimeText, create a new file called fortune.html in your repository directory: ~/Desktop/llorenzo/lab-08-if-while/
- setup an html file, and add script tags… start writing your JavaScript between the script tags
- the program should ask for a number: “Give me a number between 1 and 3, and I’ll predict your future…”
- use the parseInt function to convert the input from a string to a number (for example: num = parseInt(answer, 10))
- compare the resulting number to a number corresponding to a fortune of your own creation, e.g.:
- 1 - you will type in the word “git” many times
- 2 - you will be hungry by the end of class
- 3 - etc…
- print out the corresponding fortune to the JavaScript console…
- if the number doesn’t correspond to a fortune, print out: “you don't follow directions very well“
- example interaction is below (everything after the greater than sign (> is user input using the prompt function):
# Run 1
(prompt) Give me a number between 1 and 3, and I'll predict your future...
> 2
you will be hungry by the end of class
# Run 2
(prompt) Give me a number between 1 and 3, and I'll predict your future...
> 24
you don't follow directions very well
- save your file in SublimeText
- use git status, add, commit, and push to save your file in version control and submit it