Prep, Review

Quick Rundown of Git Commands

Git - Setting up Repositories

What command would you use to clone a remote repository?

# clone a remote repo

git clone https://your_username/your-repository-name.git

What is the command to show a remote repo?

# show remote repositories
git remote -v

# The output should look something like...
# origin  https://bzuckerman@github.com/bzuckerman/lab-08-prep.git (fetch)
# origin  https://bzuckerman@github.com/bzuckerman/lab-08-prep.git (push)

...continued...

Git - Setting up Repositories Continued

What command would you use to configure your cloned repository with your name and email?


# configure it with your name and email
git config user.name  "your name"
git config user.email "your@email.address"

Git - Saving and Sharing Changes

What’s are the commands that you would use for making, saving and sharing changes? Let’s start with just making the change and prepping it to be saved.

# (make changes)

# show the exact, line-by-line changes that you've made
git diff --color

# check on the status of your changes
git status

# stage your changes / prep them to be saved
git add --all 

# check your staged changes using git status again
git status

# (continued...)

Git - Saving and Sharing Continued…

Saving and sending to the remote repository

# save them, make sure you remember your comment by using -m!
git commit -m 'my message'

# show a history of your changes
git log --color (show your changes so far)

# send to your remote repository
git push origin master

JavaScript

A Template

What kind of file and what set up do we have write in order to start a new JavaScript program?

We have to create a bare bones web page, an .html file:

<!DOCTYPE html>
<html>
<body>
<script>
// your JavaScript goes here!
</script>
</body>
</html>

Your code goes within the script tags!

Data Types and Values

What’s a value and what’s a data type?

Data Types

What are some data types that we know?

Data Types

A value’s data type determines how that value behaves when used in functions or transformed/combined with operators.

Numbers

Numbers can be positive or negative rational numbers, like 23, -42 and 3.14. However, there are also some special values that are numbers.

Strings

What’s a string, and give an example of a string literal

A string is an ordered sequence of characters. You can tell that a value is a string if it is surrounded by single or double quotes:

"Surrounded by quotes!"

What kind of data type is this? → "5"

"When numbers are surrounded by quotes they are strings!"

Escape Characters

How do we write a backslash, quote, tab or a new line in a string?

"\\"
"\""
"\t" 
"\n"

Booleans

What’s a boolean value?

A boolean value is a data type with only two possible values:

true
false

Operators

What’s an operator and what are some examples of operators?

String Operators

We learned one operator that works on strings. What was it?

string concatenation, or +, is an operator that takes two strings and joins them:

"hello " + "there"

What is the result of this expression?

"1" + "1"

11

Comparison Operators

Name some comparison operators that return boolean values… →

Even More Comparison Operators

Logical Operators

Name some logical operators that allow you to combine boolean values. →

Boolean Expressions

You can create boolean expressions with comparison and logical operators. What is the value that results from the following expressions?

24 !== "hello"
5 === "5"
true && false
false || true
true
false
false
true

More Boolean Expressions

false && true || true
false && (true || true)
5 < 2 || 8 > 20
var login = "albert";
var password = "secret";
login === "albert" && password === "secret"
true
false
false
true

Not

There’s one more logical operator, not.

! true
! (5 > 10)
! (true && true)
false
true
false

Boolean Expressions Give Back Boolean Values!

Unary Operators

Unary Operators only have a single operand to the right:

What’s the operator that gives back the type of a value?

typeof - gives the type of a value (Number, String, etc.)

typeof

Again, typeof is:

What would we get with this code:

typeof -12
typeof "98.6"
typeof (20 === 20)
typeof NaN

Functions

What’s a function? What’s a function call? What are arguments?

Calling Functions

How do you call or execute a function?

prompt("What is your name?")

When you see parentheses - ( )’s - after a function name, that function is being called or executed

Built-in Functions

JavaScript comes with many built-in functions. We know three; what are they and what do they do?

Some Functions Return Values

What type of value does prompt always return? What type of value does parseInt always return?

Using Prompt With Variables

Remember that the function prompt gives back a value. To retain that value, you have to hold it in a variable:

var answer = prompt("Yes or no!?");

Conditionals

Blocks of Code

Curly braces denote statements of code that are grouped together. Everything within the curly braces below is considered part of the if statement. Blocks of code must start and end with curly braces…

... {
	// code wrapped by curly braces
} 

Conditionals…

What kind of statement would we use to execute code if a condition is true?

An if statement…

if (some_boolean_expression) {
	// do stuff here if expression is true
}

Conditionals Continued

What kind of statement would we use to execute code one branch of code if a condition is true and another branch of code otherwise?

if (some_boolean_expression) {
	// do stuff here if expression is true
} else {
	// do stuff here if expression is false
}

If / Else If

What kind of statement would we use to execute multiple branches of code based on multiple chained conditions?

Use if / else if statements

if (boolean_expression_1) {
	// do stuff here if expression 1 is true
} else if (boolean_expression_2) {
	// do stuff here if expression 2 is true
} else if (boolean_expression_3) {
	// do stuff here if expression 3 is true
}

If / Else If

Usage

Repeat That Again?

What construct do we use if we want to execute a block of code multiple times without writing it multiple times?

For Loop Dissected

A for loop consists of the keyword, for, and three parts, separated by a semicolon, contained within parentheses:

You can use the variable that you declare in the initialization within your for loop!

For Loop Parts

//    initialization
//    |        condition
//    |        |       afterthought/increment
//    |        |       |
for(var i = 0; i <= 5; i = i + 1) {
	console.log(i);
}

Counting By 3’s

Create a for loop that counts from 0 up to and including 9 by 3’s?

for(var i = 0; i <= 9; i = i + 3) {
	console.log(i);
}