diff --git a/back-end/arrays.md b/back-end/arrays.md index 2eb6092..8993d7b 100644 --- a/back-end/arrays.md +++ b/back-end/arrays.md @@ -51,7 +51,7 @@ Notice that in the previous examples, the items in a given list are all of the _ students = ["Cindy", "Josiah", "Rigo"] ``` ->To describe what the previous line of code does, one might say, "The `students` variable stores an Array of Strings. This array has 3 elements." +>To describe what the previous line of code does, one might say, "The `students` variable stores an Array of Strings representing student names. This array has 3 elements."
@@ -72,7 +72,7 @@ students = ["Cindy", "Josiah", "Rigo"] ### Accessing Elements -To access one element from an array, bracket notation and a number that corresponds with that element should be used. As weird as it may seem, counting starts with 0 in most programming languages. That number is referred to as an index position. +To access one element from an array we use bracket notation and a number that corresponds with that element. That number is referred to as an index position. As weird as it may seem, counting starts with 0 in most programming languages. Through reading the code snippets below, one can infer that the first element is in index position 0, and counting increments by 1. @@ -124,15 +124,34 @@ puts students[2]

+## Practice + +Create a new project (aka directory). Make 1 file - `arrays.rb`. In that file: +- Declare a variable that stores an Array of at least 4 Strings. +- Declare a variable that stores an Array of at least 4 Integers. +- Declare a variable that stores an Array of at least 4 Floats. +- Declare a variable that stores an Array of at least 4 Booleans. +- [_Intentionally open-ended_] Demonstrate your understanding of index positions in this file. You can write an explanation, provide some examples with the Arrays you've created, or anything else. + +## Check For Understanding + +Please create a section in your Mod 0 Gist for **Arrays** and record your answers to these questions. (Including the question is very helpful!) +- How confident do you feel with the content on Arrays so far? +- Is there any additional learning you need or want to do before moving to the next lesson? +- What questions do you have about Arrays? + +## Extension +The work below is meant as optional work to be completed and explored outside of the live Mod 0 sessions. This work is encouraged, but not required. + ### Array Methods -In most cases, a developer want to modify data in an Array at one point or another. Today, we will learn a number of ways to do that. They will probably not satisfy your every question of "How does X app do Y?" but this will lay an important foundation for the concept of Array methods, and some strategies to get that information you are craving! +At one point or another, a developer will need to modify data in an Array. Today, we will learn a number of ways to do that. They will probably not satisfy your every question of "How does X app do Y?" but this will lay an important foundation for the concept of Array methods and some strategies to get that information you are craving! An Array method is a piece of functionality that is built into the Ruby language, intended to be used on Arrays specifically. Each method has a specific job to perform; we can use it if we want, but we can't modify a built-in method. There are many Array methods - like anything else in programming, you will memorize a handful that you regularly use, then look to documentation for those you don't use as regularly. ### Array Methods Syntax -To use an Array method in Ruby, we first must tell Ruby which Array we want to perform the method on. After that, a dot or period, followed by the name of the method. +To use an Array method in Ruby, we first must tell Ruby which Array we want to perform the method on. After that, a dot or period (called dot syntax), followed by the name of the method. ```ruby students = ["Cindy", "Josiah", "Rigo"] @@ -143,6 +162,7 @@ p students >To describe what the previous line of code does, one might say, "This line of code calls the `pop` method on the `students` Array." +
### Learning From Reading Code You Don't Know @@ -153,7 +173,7 @@ Since researching and reading documentation can sometimes be time-consuming, ano

Array Methods & Learning Strategies:

-

You've seen the syntax for the pop method but its utility was not explained. Before going down a potential rabbit hole in Google, open up irb. Declare an Array with 3 elements. Use the pop method with the syntax you learned earlier. Call the Array and observe the change that has been made since you initially declared it. Go through this process again, with the same Array. What can you infer the pop method does? Check Google (remember, ruby-docs has the most reliable documentation) to confirm your inference. Write this down!

+

You've seen the syntax for the pop method but its utility was not explained. Before going down a potential rabbit hole in Google, open up irb. Declare an Array with 3 elements. Use the pop method with the syntax you learned earlier. Call the Array and observe the change that has been made since you initially declared it. Go through this process again, with the same Array. What can you infer the pop method does? Check Google (remember, ruby-docs has the most reliable documentation) to confirm your inference. Write this down!

Your next task is to learn what the push, shift and unshift Array methods do. Consider - how easy or hard did the work you did for pop feel? Do you want to follow the same steps to learn about the other methods, or go straight to ruby documentation to learn about the other 3? Act on whatever you decide, and be sure to write down your learnings about these methods.


@@ -161,30 +181,11 @@ Since researching and reading documentation can sometimes be time-consuming, ano

Talking and Writing about Code

In your notebook, write down the code that follows, then write a sentence that describes what that line of code does:

+

ticket_prices = [87, 67, 99, 90, 87]

ticket_prices.length

-## Check For Understanding -Create a new project (aka directory) and initialize a Git repository in it. Make 1 file - `arrays.rb`, and _make an initial commit_. In that file: -- Declare a variable that stores an Array of at least 4 Strings. -- Declare a variable that stores an Array of at least 4 Integers. -- Declare a variable that stores an Array of at least 4 Floats. -- Declare a variable that stores an Array of at least 4 Booleans. -- _Commit your work_. -- Call 1 of each of the 4 methods you learned, on each of the 4 arrays you created above. On the line of code above that, write (in a Ruby comment) an explanation in plain English as to what impact calling that method will have on that specific array. -- _Commit your work_. -- [_Intentionally open-ended_] Demonstrate your understanding of index positions in this file. You can write an explanation, provide some examples with the Arrays you've created, or anything else. -- _Commit your work_. -- Use the Ruby Documentation to learn about one additional Array method of your choice. Provide an explanation and example to demonstrate your understanding of it. (Consider bookmarking the official Array docs!) -- _Commit your work_. - -Create another file in the same directory, name it `self-evaluation.md`. In Markdown, answer the following questions: -- How confident do you feel with the content on Arrays so far? -- Is there any additional learning you need or want to do before moving to the next lesson? -- What questions do you have about Arrays? -- _Commit your work_. -After you've completed the tasks above, push your work up to a new GitHub repository. Provide the GitHub repository link in the submission form.


diff --git a/back-end/conditionals.md b/back-end/conditionals.md index f2ab737..f194602 100644 --- a/back-end/conditionals.md +++ b/back-end/conditionals.md @@ -95,9 +95,9 @@ end The following example checks if a store is open, and prints out a statment if the store is indeed open: ```ruby -is_open = true +greeting = "Hello" -if is_open == true +if greeting == "Hello" puts "Let's go!" end ``` @@ -110,15 +110,15 @@ end ### `else` -In the previous exercises, when the condition evaluates to false, we don't see any output. In order to have a default response that runs when the condition is false, we need an `else` statement. Here's an example with the `is_open` variable for the store. +In the previous exercises, when the condition evaluates to false, we don't see any output. In order to have a default response that runs when the condition is false, we need an `else` statement. Here's an example with the `greeting` variable for the store. ```ruby -is_open = true +greeting = "Hello" -if is_open == true +if greeting == "Hello" puts "Let's go!" else - puts "Oops. Looks like that store is closed now." + puts "Goodbye then." end ``` @@ -166,13 +166,18 @@ Notice that each of the previous examples have **one** `end` keyword. That is pa +## Self-Teach +Part of what you'll experience at Turing is learning a technical topic on your own. Practicing this skill at Turing will get you prepared for the job where you will do this often. + +Take time between now and your next session to self-teach the following section. + ## Logical Operators There are three logical operators in Ruby; we will learn two today: -- `&&` or `and` -- `||` or `or` +- `&&` (Logical And Operator) +- `||` (Logical Or Operator) -### `&&` or `and` +### `&&` This logical operator will check two values, and both **must** be true in order for it to return `true`. Examples follow: @@ -193,7 +198,7 @@ age < 30 && time < 2.0 # false (neither meet requirement) ``` -### `||` or `or` +### `||` This logical operator will check two values, and _one_ or _both_ must be true in order for it to return true. Examples follow: ```ruby @@ -240,6 +245,7 @@ Now that you know about logical operators and `if statements`, let's combine tha ## Check For Understanding -Follow the directions in the README of this GitHub repository, and submit your fork in the submission form. +- Follow the directions in the README of this GitHub repository. +- Add the link to your repository to your Mod 0 Gist in a section called `Conditionals`.


\ No newline at end of file diff --git a/back-end/data_types.md b/back-end/data_types.md index fd54aa5..79539ad 100644 --- a/back-end/data_types.md +++ b/back-end/data_types.md @@ -57,13 +57,14 @@ To connect to how these data types are used in an application we all have some e

Deciding on a Data Type

-

For each of the items listed below, determine which Data Type seems most appropriate to store it as. If you are unsure of any, start a discussion in your Slack small group.

+

For each of the items listed below, determine which Data Type seems most appropriate to store it as. If you are unsure of any, start a discussion in your Slack group.


-## Check For Understanding +## Addtional Practice +This practice work is encouraged, but not required. -[Follow the directions in the README of this GitHub repository](https://github.com/turingschool/m0_be_iteration/), and submit your fork in the submission form. +[Follow the directions in the README of this GitHub repository](https://github.com/turingschool/m0_be_iteration/).

diff --git a/back-end/methods-fasttrack.md b/back-end/methods-fasttrack.md new file mode 100644 index 0000000..259b5c5 --- /dev/null +++ b/back-end/methods-fasttrack.md @@ -0,0 +1,311 @@ +--- +layout: lesson +title: Methods +--- + +## Learning Goals + +- Explain the purpose of methods +- Use built-in methods on appropriate objects based on data type +- Define and call methods in Ruby +- Use and explain the flow of data with arguments and parameters +- Describe the purpose of a return value + +## Vocabulary + +- method +- define +- execute or call +- return +- parameter +- argument + +## Methods + +A Method is a package of instructions. Once a method is defined, it can be used as many times as needed. Ruby provides many built-in methods that developers can use. + +## Defining Our Own Methods + +There are many methods that are built into the Ruby language. Those are great and you will use them regularly as a developer (and you'll explore them later today!). There will also be times when you need to write your own method to solve a unique problem in the application you are building or maintaining. + +### Syntax for Defining a Method + +To define our own method, we'll use the following guidelines: +- The `def` and `end` keywords act like bookends for the code block. +- Following the keyword `def`, we assign our method a name. It's best if the name describes what the method _does_. +- The code block is indented and contains all of the "instructions" for what the method should do when it is called. +- The value that follows the `return` keyword is the data that the method will return when it is called. + +In the method below, the code block has only one line, but it's important to note that there could be many lines of code within the code block, describing the steps that a method should follow. You can even include other things we've learned like conditionals and built-in methods within your code block. + +```ruby +# method definition +def greet_a_texan + return "Howdy, partner!" +end +``` + +After defining a method, nothing will _appear_ to happen. The interpreter that reads the Ruby code will read it, and be aware of that set of instructions, but it won't carry out those instructions until it is explicitly told to do so. + +### Syntax for _Calling_ a Method + +To instruct the interpreter to carry out the instructions in a method, the developer must write code to call or execute that method. Simply writing the name of the method, `greet_a_texan` in this example, calls or executes the method. When we call this method by writing the name of the method, it triggers the "instructions" held within the code block of that method. Now, this method by itself only returns the string "Howdy, partner!" - we still need to use a `puts` command to _see_ that return value in the console. + +```ruby +# method call +greet_a_texan +``` + +### Naming Conventions + +Since methods provide action to a program, they should be named accordingly; it's best practice to start them with a verb. Like variables, Ruby methods should use `snake_case` when they involve more than one word and should be written carefully to describe their role specifically without being overly verbose. + +Examples of function names that follow best practices: +- `get_user_input` +- `display_followers` +- `add_two_numbers` +- `find_longest_name` + +In the example above, the developer chose the method name of `greet_a_texan`. Method names should usually include verbs, since methods _do_ something. The definition just tells the program that it's a set of directions ready to be followed; the _method call_ is what makes the code in the method execute, or follow the packaged directions. You can call a method as many times as you want, once it's been defined! + +### A Method Metaphor + +Often, we want to use a method to perform an action on or with a piece of data. Think back to those built-in methods. We didn't simply call the `odd?` method by itself. We called it on an Integer object and it returned a Boolean value. We can do the same thing with the methods we define. Think of your method like a machine with inputs and outputs. + + + +If this were a cookie machine, for example, the machine would take in all of the raw ingredients (eggs, flour, sugar, etc.) and perform some steps to make the cookies: +1. Mix ingredients to make dough +2. Place dough balls on a baking sheet +3. Bake at 350 degrees for 10 minutes +4. Let cookies cool +5. Serve the cookies on a plate + +We can imagine that our cookie machine would do all of those steps and then give us back freshly baked, warm cookies! + +Let's expand this example to any kind of machine. We give the machine the raw materials, it does something with those materials, and then returns the final product. This is _very_ similar to what we are doing with our own methods. We give the method some piece of data or information (or even multiple pieces of information) and then the method does something with that information and spits out a return value. + +
+

Think About It

+

Look at the method call below and make a guess about how this might be different from the previous method example.

+
+  greet_a_texan("Kaitlyn")
+  # => "Howdy, Kaitlyn!"
+ +
+
+ +Without possibly having all the information about Ruby syntax, you probably made some connection as to what might be happening with the previous code snippet. The `greet_a_texan` method was called, but this time, we were able to dynamically change the name of the person we were greeting! + + +### Arguments & Parameters + +Arguments are the technical term for the inputs to a method such as the String that was provided in the parenthesis after the method name in the previous example. As developers, we have the control to name the parameters, or placeholders, for the data that will be passed in. Those names should follow variable name conventions and be concise, yet descriptive. The number of arguments passed in should match the number of parameters declared. + +```ruby +# name is a parameter +def greet_a_texan(name) + return "Howdy, #{name}!" +end + +# "Kaitlyn" is the argument for this method call +puts greet_a_texan("Kaitlyn") +# => "Howdy, Kaitlyn!" + +# "Brian" is the argument for this method call +puts greet_a_texan("Brian") +# => "Howdy, Brian!" +``` + +> **Note:** You'll notice that we are using the `puts` command in front of the method call this time. This allows us to also **see** the return value of the `greet_a_texan` method printed to the console, but it is not necessary. The code `greet_a_texan("Kaitlyn")` by itself does return the string "Howdy, Kaitlyn!", but if we want to see it printed in the console, we will need to use `puts` or `print` along with the method call. + +
+ +
+

Practice

+ + +
+
+ +### Return Values + +A return value is either: + +- defined _explicitly_ using the `return` keyword OR +- is the last line of code run, if no `return` keyword was used + +In the `subtract` example below, the return value will be whatever is stored in the `difference` variable. If 10 and 7 are passed in as arguments, the return value is 3 because the last line of the method uses the `return` keyword to return the `difference` variable. This is called an explicit return. + +```ruby +def subtract(bigger, smaller) + difference = bigger - smaller + return difference +end + +subtract(10, 7) +# => 3 (return value is 3 since it is stored in the difference variable, and the last line of the method uses the return keyword) +``` + +In the `add` example below, the return value is an Integer or Float, based on what values were passed in as arguments. If 2 and 3 are passed in, the return value is 5. This is called an implicit return. Ruby automatically returns the value of the last expression in a method if no `return` is present. For this reason, if we want to return the value of the last expression in a method, we usually do not use the `return` keyword, as it is considered redundant and unnecessary. + +```ruby +def add(num1, num2) + num1 + num2 +end + +add(2, 3) +# => 5 (return value is 5 since that's the sum of 2+3, and on the last line of the method) +``` + +
+

Best Practices

+

Typically, we do not include an explicit return unless it is absolutely necessary. Since ruby methods automatically return the value of the last line, it's common practice to use implicit returns like in the example above.

+
+
+ +### Be Careful with puts Inside of Your Method + +In the `say_goodbye` example below, notice we included the `puts` command in the last line of the method instead of returning a data point. The return value is `nil` because the last line of code is `puts "See you later"`, and `puts` is a built-in command with a return value of `nil`. This is generally not a best practice, because the method doesn't return any usable data. + +```ruby +def say_goodbye + puts "See you later!" +end + +say_goodbye +# "See you later!" will be printed to the console +# The return value is nil because puts is on the last line of the method and the return value of the puts method is always nil +``` + +>**Key Point:** Up until now, we've use the `puts` and `print` commands to see values printed to the console. Be careful not to confuse what you see in the console with the return value of the method -- these are two different things. We use `puts` and `print` to **see** data in the console, but what we see in the console is **not always** the return values. + +
+ +### Storing a Return Value + +The examples we've looked at so far call the method and execute the code within the method, but the return values go nowhere/can never be used in the program again. Many times, we'll store the return value of a method in another variable, as modeled below: + +```ruby +def add(num1, num2) + num1 + num2 +end + +sum1 = add(2, 3) +sum2 = add(7, 9) + +puts sum1 +puts sum2 +``` + +
+ +
+

Practice

+ + +
+ +
+ +
+

Key Points Summary

+ +
+
+ +## Self-Teach +Part of what you'll experience at Turing is learning a technical topic on your own. Practicing this skill at Turing will get you prepared for the job where you will do this often. + +Take time between now and your next session to self-teach the following section. + +## Warm-Up for Built-In Methods + +
+

Exploration: PART 1

+

Fork, then run the code in this replit and observe the output.

+

Think: How did each line of code, produce each respective line of output? Which parts make sense, and which are confusing?

+
+
+ +## Methods + +A Method is a package of instructions. Once a method is defined, it can be used as many times as needed. Ruby provides many built-in methods that developers can use. + +The code snippet that follows was part of the previous Exploration activity: + +```ruby +p 14.odd? +``` + +>To describe the code snippet in English, one could say, "the `odd question mark` method is being called on the Integer 14." Since 14 is not odd, `false` will be the return value. The `p` command prints that return value of `false` to the console. + +In this particular example, the utility of the `odd?` method is to determine if an Integer is odd, or not. It answers the question with a Boolean (`true` or `false`). The benefit of having this method built into Ruby is if a developer needs to check if a number is odd or not, they only have to type `.odd?` anywhere they need to check. If they didn't have a pre-packaged method, they'd have to write several lines of code involving logic, every time they want to check if an integer is odd. **Reusability is what makes methods so powerful.** + +
+
+

Exploration: PART 2

+

In the same replit from the first exploration, comment out the code from Part 1, and uncomment the code under Part 2.

+ +
+
+ +The following code snippet demonstrates that a method can be called on a variable assigned to data: + +```ruby +new_string = "Hello World" +p new_string.upcase +``` + +>To describe the code snippet in English, one could say, "the first line declares a variable called `new_string` and the second line calls the `upcase` method on the `new_string` variable." As a result, the method will return a String object where any letter character in the original String stored in `new_string` will now be capitalized. The `p` command prints that return value of `"HELLO WORLD"` to the console. However, it's important to note that the original data stored in `new_string` is not modified permanently. + +
+
+

Exploration: PART 3

+

In the same replit, comment out the code from Part 2, and uncomment the variable declarations and first method call under Part 3.

+ +
+
+ +
+

Key Points

+ +
+
+ +## Check For Understanding + +- Complete the tasks in this repository. +- Add a link to your respository under a new section of your Mod 0 Gist called `Methods`. + + +
+
+
\ No newline at end of file diff --git a/back-end/testing-fasttrack.md b/back-end/testing-fasttrack.md new file mode 100644 index 0000000..1bb1d66 --- /dev/null +++ b/back-end/testing-fasttrack.md @@ -0,0 +1,251 @@ +--- +layout: lesson +title: Intro to Testing +--- + +## Learning Goals + +- Explain what a test is (in software development) +- Read an `rspec` test and explain what it is asking for +- Write simple Ruby classes that meet requirements of pre-written tests + + +## Vocabulary + +- assertion +- rspec +- Test Driven Development +- test +- testing framework + + +## Tests + +In software, it is common to write automated tests to verify that our code behaves the way we want it to and doesn't have any negative or unexpected side affects (bugs) on any other part of a project. These tests are usually written in the same language the code itself is in, with the help of a tool that is usually categorized as a testing framework. + +### File Structure + +There are many ways a file structure can be designed when there are many files in a project. A common convention, and one you'll use in Mod 1 is illustrated: + +``` +project_name +|-lib + |-name_of_class.rb + |-name_of_class1.rb +|-spec + |-name_of_class_spec.rb + |-name_of_class1_spec.rb +``` + +(Note: The directory and file names do not start with `|-`; that is just a way to notate the structure.) + +## `rspec` + +rspec is a tool, classified as a testing framework, that allows us to write automated tests that will test our Ruby code. Just like we must write Ruby exactly as it's intended to be used, we must carefully use the syntax and methods available within `rspec`. The official `rspec` documentation may at first seem dense; it has much more than what you will even get into in Mod 1, but it's great to be aware of and start getting comfortable reading if you need a resource during or after this lesson. + +### Setup `rspec` + +While navigated to the project that is applicable, run this command in the Terminal to add the `rspec` framework to that project. This command only needs to be run once per project. + +```bash +$ gem install rspec +``` + +The first two lines of every test (or spec) file should be: + +```ruby +require 'rspec' +require './lib/.rb' +``` + +To run a test, or spec, file, in the Terminal: + +```bash +rspec .rb +``` + +
+

Documentation Reading

+

There are times when you need to follow directions exactly, and times when you might need to adjust to add in custom information. In the previous examples, we can infer that name_of_class_spec is not actually a file name, but the documention is intending to show the reader that the last part of the file name should be _spec, preceded by the name of the class the test file will be testing.

+
+
+ +### Syntax and Anatomy of an `rspec` Test + +>A series of code snippets is provided to show a progression of a test file being built. In Mod 0, you do not need to be proficient in writing tests; this progression is shown to help you focus on each piece with a paired explanation. + +The code snippet that follows shows the skeleton of an `rspec` test. The class it is testing is named `Student`, and lives in a file with the same naming convention. + +After requiring `rspec` and the code file, a `describe` block is opened up, where `rspec` expects the class name. The `do` and `end` open and close the block, similar to other Ruby structures. The code snippet that follows is not enough to _test_ any code; but it's the first step: + +```ruby +# student_spec.rb +require 'rspec' +require './lib/student' + +describe Student do + +end +``` + +In the next code snippet, one test has been added inside of the `describe` block, to test a very small thing - this test verifies that when an object instance is created, it is actually an instance created from the class it should be created from. + +This `describe` block contains: +- An `it` statement - a String that uses plain English to describe what _it_ (the test) tests +- Definition of a variable that stores a student object +- An assertion written with `rspec` + +```ruby +# student_spec.rb +require 'rspec' +require './lib/student' + +describe Student do + it 'is an instance of student' do + student = Student.new('Penelope') + expect(student).to be_a Student + end +end +``` + +The final snippet adds a test (in a new `it` block) that checks if a student object instance has a name attribute that matches the value that was passed in upon creating the object instance: + +```ruby +# student_spec.rb +require 'rspec' +require './lib/student' + +describe Student do + it 'is an instance of student' do + student = Student.new('Penelope') + expect(student).to be_a Student + end + + it 'has a name' do + student = Student.new('Penelope') + expect(student.name).to eq 'Penelope' + end +end +``` + +The following code snippet provides an annotation for each line of this same file: + +```ruby +# ensures the rspec testing framework is available for use in this file +require 'rspec' +# allows the spec file to read the contents of the student file +require './lib/student' + +# start of describe block; one per class/test file +describe Student do + # start of it block for an individual test + # the string should briefly describe in plain English what is being tested + it 'is an instance of student' do + # create a student object instance + student = Student.new('Penelope') + # assert that the student is from the Student class + expect(student).to be_a Student + end + + it 'has a name' do + student = Student.new('Penelope') + # assert that the student has a name property which matches what was passed in + expect(student.name).to eq 'Penelope' + end +end +``` + +The code that follows would allow the previous tests to pass (which should live in the `student.rb` file): + +```ruby +class Student + attr_reader :name + + def initialize(name) + @name = name + end +end +``` + +
+

Explore rspec

+

Follow the directions to set up a small project that uses rspec:

+
    +
  • Create a directory called intro_testing
  • +
  • Install the rspec gem using the command noted earlier in the lesson
  • +
  • Create two directories: lib and spec
  • +
  • Create one file inside of each of the new directories: student.rb and student_spec.rb respectively
  • +
  • Copy and paste the code for the Student class and the two tests that are provided above, into the appropriate files
  • +
  • Run rspec spec/student_spec.rb in your Terminal
  • +
  • Delete the attr_reader from the Student class and re-run the tests; observe what happens
  • +
  • Delete the entire initialize method from the Student class and re-run the tests; observe what happens
  • +
  • Delete the entire Student class and re-run the tests; observe what happens
  • +
  • Bring back all the original code into the Student file and re-run the tests to ensure they now pass
  • +
+

Challenge: Write a new test, that checks that the student has a dynamic age property. Write the code to make the test pass.

+
+ + +## Test Driven Development + +Test Driven Development is a common process for writing software. It entails writing the tests before the code, then using the test to guide the developers while writing the actual code. This lesson will provide some _exposure_ to the process, and the Mod 1 curriculum will dive deep into it and require it of students. + +When provided the test file that follows (the same one we've been looking at in previous examples), one can turn that code into directions that inform what should be written into the `Student` class. + +```ruby +require 'rspec' +# write your code in a file named student +require './lib/student' + +describe Student do + it 'is an instance of student' do + # since a student object is being created from a Student class, + # write a class named Student + + # ALSO - since an argument is being passed to Student, the initialize method needs to accept one + student = Student.new('Penelope') + expect(student).to be_a Student + end + + it 'has a name' do + student = Student.new('Penelope') + # since we need to call the name attribute and get back the string that was passed in, + # we need an attr_reader for the name attribute + expect(student.name).to eq 'Penelope' + end +end +``` + +The comments in the file can help a developer write an even more accessible specification: +- Write a class named Student, in the `lib/student` file +- The class should have one dynamic attribute named `name` +- Use an `attr_reader` so the `name` can be read + +With that, the following code can be written to satisfy the tests: + +```ruby +class Student + attr_reader :name + + def initialize(name) + @name = name + end +end +``` +
+

Practice Reading Tests

+

Read the test in this file and write out a list of human-readable, clear directions you could read aloud to someone you are pairing with in order to pass the tests. One of the tests does push you to apply some learning that was not explicitly covered in this less - that was intentional! The goal is not to be perfect or perfectly correct; it's to push you to apply some other knowledge and start getting comfortable with unknown code.

+
+ +## Check For Understanding + +Create a new directory with `lib` and `test` directories inside. Use the test file that was provided in the previous activity, and write a class that satisfies those tests. Use your Git Workflow, make a GitHub repository and push your completed work up. + + +## Mod 0 Extensions + +Your Mod 1 instructors have created [this repository](https://github.com/turingschool-examples/mod-1-be-exercises/tree/main/ruby_exercises) to give you something to work on in between Mod 0 and Mod 1. Nothing is required; but students in the past have found it as helpful and aligned practice during the "down time" before Mod 1. Have fun! + +
+
+
\ No newline at end of file diff --git a/fasttrack-be/index.md b/fasttrack-be/index.md index 2c065b2..6d13e4e 100644 --- a/fasttrack-be/index.md +++ b/fasttrack-be/index.md @@ -33,15 +33,15 @@ All lessons and assignments for Mod 0 are listed below and organized into sessio ### Assignment - Complete Before Session 3 * [DTR Prep]({{ site.url}}/shared/dtr) +* [Pairing Prep]({{ site.url}}/shared/pairing) ## Session 3 ### Live Sessions * [Conditionals]({{ site.url }}/back-end/conditionals) -* [Methods]({{ site.url }}/back-end/methods) +* [Methods]({{ site.url }}/back-end/methods-fasttrack) ### Assignment - Complete before Session 4 -* Review all notes and past lessons -* Preview next session's lesson +* Complete the Self-Teach sections from the Conditionals and Methods lessons. ## Session 4 ### Live Sessions @@ -49,13 +49,13 @@ All lessons and assignments for Mod 0 are listed below and organized into sessio ### Assignment - Complete by Sunday Evening * [Problem Solving]({{ site.url }}/shared/problem-solving-fasttrack) -* [Beyond Mod 0 Plan]({{ site.url }}/shared/plan) -* [Final Reflection Video]({{ site.url }}/shared/final-video) +* [Beyond Mod 0 Plan]({{ site.url }}/shared/plan-fasttrack) +* [Final Reflections]({{ site.url }}/shared/final-reflections) ## Pre-Teach Before Mod 1 Note: You are not expected to be experts on these topics, but you should come to Mod 1 ready to ask questions about the topics covered in these lessons. -* [Hashes]({{ site.url }}/back-end/hashes) -* [Testing]({{ site.url }}/back-end/testing) +* [Hashes]({{ site.url }}/back-end/hashes-fasttrack) +* [Testing]({{ site.url }}/back-end/testing-fasttrack)

diff --git a/fasttrack-fe/index.md b/fasttrack-fe/index.md index 347b5bb..6cf7411 100644 --- a/fasttrack-fe/index.md +++ b/fasttrack-fe/index.md @@ -33,15 +33,15 @@ All lessons and assignments for Mod 0 are listed below and organized into sessio ### Assignment - Complete Before Session 3 * [DTR Prep]({{ site.url}}/shared/dtr) +* [Pairing Prep]({{ site.url}}/shared/pairing) ## Session 3 ### Live Sessions * [Conditionals]({{ site.url }}/front-end/conditionals) -* [Functions]({{ site.url }}/front-end/functions) +* [Functions]({{ site.url }}/front-end/functions-fasttrack) ### Assignment - Complete before Session 4 -* Review all notes and past lessons -* Preview next session's lesson +* Complete the Self-Teach sections from the Conditionals and Functions lessons. ## Session 4 ### Live Sessions @@ -49,12 +49,12 @@ All lessons and assignments for Mod 0 are listed below and organized into sessio ### Assignment - Complete by Sunday Evening * [Problem Solving]({{ site.url }}/shared/problem-solving-fasttrack) -* [Beyond Mod 0 Plan]({{ site.url }}/shared/plan) -* [Final Reflection Video]({{ site.url }}/shared/final-video) +* [Beyond Mod 0 Plan]({{ site.url }}/shared/plan-fasttrack) +* [Final Reflections]({{ site.url }}/shared/final-reflections) ## Pre-Teach Before Mod 1 Note: You are not expected to be experts on these topics, but you should come to Mod 1 ready to ask questions about the topics covered in these lessons. -* [Object Literals]({{ site.url }}/front-end/objects) +* [Object Literals]({{ site.url }}/front-end/objects-fasttrack)

diff --git a/front-end/arrays.md b/front-end/arrays.md index 512b929..1d4d5d2 100644 --- a/front-end/arrays.md +++ b/front-end/arrays.md @@ -51,7 +51,7 @@ Notice that in the previous examples, the items in a given list are all of the _ var students = ["Cindy", "Josiah", "Rigo"]; ``` ->To describe what the previous line of code does, one might say, "The `students` variable stores an Array of Strings. This array has 3 elements." +>To describe what the previous line of code does, one might say, "The `students` variable stores an Array of Strings which represent the names of students. This array has 3 elements."
@@ -72,7 +72,7 @@ var students = ["Cindy", "Josiah", "Rigo"]; ### Accessing Elements -To access one element from an array, bracket notation and a number that corresponds with that element should be used. As weird as it may seem, counting starts with 0 in most programming languages. That number is referred to as an index position. +To access one element from an array, bracket notation and a number that corresponds with that element should be used. That number is referred to as an index position. As weird as it may seem, counting starts with 0 in most programming languages. Through reading the code snippet in the embdedd replit that follows, one can infer that the first element is in index position 0, and counting increments by 1. (Click the green "Run" button to see the output in the Console at the bottom of the embdedded replit.) @@ -105,9 +105,28 @@ Through reading the code snippet in the embdedd replit that follows, one can inf

+## Practice + +Create a new project (aka directory). Make 1 file - `arrays.rb`. In that file: +- Declare a variable that stores an Array of at least 4 Strings. +- Declare a variable that stores an Array of at least 4 Integers. +- Declare a variable that stores an Array of at least 4 Floats. +- Declare a variable that stores an Array of at least 4 Booleans. +- [_Intentionally open-ended_] Demonstrate your understanding of index positions in this file. You can write an explanation, provide some examples with the Arrays you've created, or anything else. + +## Check For Understanding + +Please create a section in your Mod 0 Gist for **Arrays** and record your answers to these questions. (Including the question is very helpful!) +- How confident do you feel with the content on Arrays so far? +- Is there any additional learning you need or want to do before moving to the next lesson? +- What questions do you have about Arrays? + +## Extension +The work below is meant as optional work to be completed and explored outside of the live Mod 0 sessions. This work is encouraged, but not required. + ### Array Methods -In most cases, a developer wants to modify data in an Array at one point or another. Today, we will learn a number of ways to do that. They will probably not satisfy your every question of "How does X app do Y?" but this will lay an important foundation for the concept of Array methods, and some strategies to get that information you are craving! + A t one point or another, a developer will need to modify data in an Array. Today, we will learn a number of ways to do that. They will probably not satisfy your every question of "How does X app do Y?" but this will lay an important foundation for the concept of Array methods, and some strategies to get that information you are craving! An Array method is a piece of functionality that is built into the JavaScript language, intended to be used on Arrays specifically. Each method has a specific job to perform; we can use it if we want, but we can't modify a built-in method. There are many Array methods - like anything else in programming, you will memorize a handful that you regularly use, then look to documentation for those you don't use as regularly. @@ -147,24 +166,7 @@ Since researching and reading documentation can sometimes be time-consuming, ano

Hint: Just by looking at this code, it's unlikely you know what it does. What can you do to explore, learn, and confirm what it does?

-## Check For Understanding - -Create a new project (aka directory) and initialize a Git repository in it. Make 1 file - `arrays.js`, and _make an initial commit_. In that file: -- Declare a variable that stores an Array of at least 4 Strings. -- Declare a variable that stores an Array of at least 4 Numbers. -- Declare a variable that stores an Array of at least 4 Booleans. -- _Commit your work_. -- Call a different Array method on each of the 3 arrays you created above. On the line of code above each method call, write (in a JavaScript comment) an explanation in plain English as to what impact calling that method will have on that specific array. -- _Commit your work_. -- [_Intentionally open-ended_] Demonstrate your understanding of index positions in this file. You can write an explanation, provide some examples with the Arrays you've created, or anything else. -- _Commit your work_. -Create another file in the same directory, name it `self-evaluation.md`. In Markdown, answer the following questions: -- How confident do you feel with the content on Arrays so far? -- Is there any additional learning you need or want to do before moving to the next lesson? -- What questions do you have about Arrays? -- _Commit your work_. -After you've completed the tasks above, push your work up to a new GitHub repository. Provide the GitHub repository link in the submission form.


diff --git a/front-end/conditionals.md b/front-end/conditionals.md index 474acce..5429020 100644 --- a/front-end/conditionals.md +++ b/front-end/conditionals.md @@ -166,13 +166,18 @@ Notice that code inside the `else` statement will only run when none of the prev +## Self-Teach +Part of what you'll experience at Turing is learning a technical topic on your own. Practicing this skill at Turing will get you prepared for the job where you will do this often. + +Take time between now and your next session to self-teach the following section. + ## Logical Operators There are three logical operators in JavaScript; we will learn two today: -- `&&` or `and` -- `||` or `or` +- `&&` (Logical And Operator) +- `||` (Logical Or Operator) -### `&&` or `and` +### `&&` This logical operator will check two values, and both **must** be true in order for it to return `true`. Examples follow: @@ -193,7 +198,7 @@ age < 30 && time < 2.0 // false (neither meet requirement) ``` -### `||` or `or` +### `||` This logical operator will check two values, and _one_ or _both_ must be true in order for it to return true. Examples follow: @@ -246,6 +251,7 @@ Now that you know about logical operators and `if statements`, let's combine tha ## Check For Understanding -Follow the directions in the README of this GitHub repository, and submit your fork in the submission form. +- Follow the directions in the README of this GitHub repository. +- Add the link to your repository to your Mod 0 Gist in a section called `Conditionals`.


\ No newline at end of file diff --git a/front-end/data_types.md b/front-end/data_types.md index e4ac383..ee08f0c 100644 --- a/front-end/data_types.md +++ b/front-end/data_types.md @@ -27,11 +27,11 @@ JavaScript was created to make the web more dynamic. It is a scripting language JavaScript can be client-side and server-side, meaning that it can be used to control user-facing interfaces (e.g. browsers) as well as handle the server-side extensions that connect with a database. -It’s a highly versatile and flexible language, favoring configuration over convention. This means that, when you’re working in JavaScript, there are TONS of different ways to accomplish the same task. Sometimes one is better than another, but often there’s not **ONE** right way to do something. JavaScript has become the most commonly used language of the web! +It’s a highly versatile and flexible language, favoring configuration over convention. This means that when you’re working in JavaScript, there are TONS of different ways to accomplish the same task. Sometimes one is better than another, but often there’s not **ONE** right way to do something. JavaScript has become the most commonly used language of the web. ## Where To Run Code -By the end of this session, you'll be able to use a feature of the Chrome browser called the Dev Tools, specifically a tool within it called the Console, to run and check your code. This is a great tool for a beginner, as well as a seasoned software developer, to have. This Console will allow you to explore and learn JavaScript and test out code you've written in a low stakes environment. It is quick and easy to open up Chrome and run your code immediately. +By the end of this session, you'll be able to use a feature of the Chrome browser called the Dev Tools, specifically a tool within it called the Console, to run and check your code. This is a great tool for beginners and is used regularly by all software developers. This Console will allow you to explore and learn JavaScript and test out code you've written in a low stakes environment. It is quick and easy to open up Chrome and run your code immediately. ### Chrome Dev Tools Console: Tips & Tricks @@ -78,6 +78,7 @@ To connect to how these data types are used in an application we all have some e
  • Age
  • Number of Likes
  • Balance on a bank account
  • +
  • Zip Code
  • Currently online
  • Daily countdown to a big event
  • Caption for an image
  • @@ -86,7 +87,7 @@ To connect to how these data types are used in an application we all have some e ## Variables -Pieces of data in the various types we've discussed so far are valid JavaScript code just as they are. We can demonstrate that by typing `"helloworld@gmail.com"` or `37` or `false` into the Chrome Dev Tools Console. We know they are valid because we don't get an error. If `helloworld@gmail.com` is typed in, we _will_ get an error, and possibly a helpful suggestion! +Pieces of data in the various types we've discussed so far are valid JavaScript code just as they are. We can demonstrate that by typing `"helloworld@gmail.com"` or `37` or `false` into the Chrome Dev Tools Console. We know they are valid because we don't get an error. If `helloworld@gmail.com` is typed in, we _will_ get an error, and possibly a helpful suggestion, because we didn't include quotations around that string data! However, if we ever want to reference that email address ever again in our code, the only way would be to read that part of the screen and manually type it out again - and that's not going to make for a very efficient application. @@ -173,34 +174,30 @@ This lesson exposed the reader to the Chrome Dev Tools Console as an _option_ an **One difference to note, at this stage in knowledge and learning, and being able to see the output.** - In the Chrome Dev Tools Console, one can type the name of a variable to _call_ it, and after pressing the return key, the Console will display the value of that variable after the `<` symbol. - When writing code in VS Code, simply typing the name of a variable will not result in showing the human the value of the variable. Two steps need to be taken: -1. Instruct the program to print out the value of the variable using the `console.log()` method. `console.log(depositPaid)` is an example of a `console.log` statement that will print out the value of the `depositPaid` variable. -2. Run the code. In the Terminal, while navigated to the directory that the file containing the code you want to run, run `node filename.js` and the `console.log` statements should print out. Additionally, any errors in the code may produce an error message at this time. +1. Instruct the program to print out the value of the variable using the `console.log()` function. `console.log(depositPaid)` is an example of a `console.log` statement that will print out the value of the `depositPaid` variable. +2. Run the code. In the Terminal, navigate to the directory that the file containing the code you want to run is in, type `node filename.js` and the `console.log` statements should print out. Additionally, any errors in the code may produce an error message at this time. The Check For Understanding will provide a practice opportunity for this section. -## Check For Understanding - -_Complete this CFU **after** you've done the live GitHub lesson._ +## Practice -Use everything you’ve learned with VS Code, Git, GitHub, Data Types and variables, complete this challenge: +*Note:* If at anytime you have questions, please ask them in your slack channel. This is the main resource we will use for asking questions at Turing. 1. Create a new directory called `variablePractice`. 1. Inside that directory, create a file called `variables.js`. -1. Initialize `git` inside of the directory. -1. Commit your work (Think about what message should you use here). -1. Go to GitHub and create a repository with the same name - `variablePractice`. -1. Push your local directory to GitHub by following the instructions. 1. In your `variables.js` file, add a few variables that are assigned to Strings. -1. Commit your work. 1. In your `variables.js` file, add a few variables that are assigned to Numbers. -1. Commit your work. 1. In your `variables.js` file, add a few variables that are assigned to Booleans. -1. Commit your work. 1. In your `variables.js` file, leave the original String variables as declared, but add some code to _reassign_ them to different values. 1. Write several `console.log` statements. -1. `NEW` Run your code by going to the Terminal and running `node variables.js` - make sure you are inside the `variablePractice` directory when doing so. -1. Commit your work. -1. Push your changes to GitHub. +1. `NEW` Run your code by going to the Terminal and running `node variables.js` - make sure you are inside the `variablePractice` directory when doing so. You should see the output of your JavaScript file in the terminal. If done correctly, anywhere you have a `console.log` statement, it should print to your terminal. + +## Check For Understanding + +Please create a section in your Mod 0 Gist for **Data Types** and record your answers to these questions. (Including the question is very helpful!) +- How confident do you feel with the content on Data Types so far? +- Is there any additional learning you need or want to do before moving to the next lesson? +- What questions do you have about Data Types? + -Please submit the link to your GitHub repository in the submission form.

    diff --git a/front-end/for.md b/front-end/for.md index 6e3eaec..91083c2 100644 --- a/front-end/for.md +++ b/front-end/for.md @@ -15,35 +15,6 @@ title: For Statements - for statement - initialization -## Warm-Up - -Write 1-2 sentences to explain the code snippet below, using as many technical vocabulary terms as possible. - -```javascript -var emails = [ - "kaitlyn@turing.edu", - "justina@turing.edu", - "amy@turing.edu", - "launa@turing.edu", - "nikki@turing.edu", - "naomi@turing.edu" -]; -``` - -## Discovery - -Work through the activity that follows to practice reading unfamiliar code and working to make sense of it. - -
    -

    Reading a for loop

    -
      -
    • Open this replit and click "fork".
    • -
    • Run the code in the replit. Read through the code for each for statement and identify the portion of the output that belongs with it. What do you notice? Work to identify which piece of the code corresponds to a change in the output.
    • -
    • If questions or wonderings such as "I wonder what would happen if we did X instead of Y...?" - there is nothing stopping you from trying that out, and finding the answer right now! You can edit the existing code, copy-and-paste code snippets then modify, or write something out yourself.
    • -
    -
    -
    - ## `for statement` Watch this video to see an explanation of the code snippet shown below. @@ -59,6 +30,7 @@ for (var i = 0; i < 4; i++) { // --> 3 ``` +Refer to this outline while reading the explanation below. ``` for ([initialization]; [condition]; [final-expression]) { [statement] @@ -82,16 +54,6 @@ for ([initialization]; [condition]; [final-expression]) { ## Practice -
    -

    Explaining Code

    -
      -
    • Choose one of the for statements that was in the replit used for the Discovery activity.
    • -
    • To review and solidify what you saw in the video, prepare a verbal or written explanation of what your selected for statement does, in as much detail as possible. Take note of things you find yourself wondering or feeling confused about.
    • -
    • Do some research to try and answer your own question or go to your Slack small group!
    • -
    -
    -
    -

    Writing Code

    For these tasks, utilize your notes but do not, under any circumstance, copy-and-paste code. It's recommended you write the code in a new replit file.

    @@ -125,7 +87,7 @@ for (var i = 0; i < fruits.length; i++) {
  • Change fruits[i] to [i]. Re-run the code - has the output changed? Revert the changes with the keyboard shortcut cmd + z.
  • Change fruits[i] to fruits. Re-run the code - has the output changed? Revert the changes with the keyboard shortcut cmd + z.
  • -

    If you have questions about how any of those exercises worked, use Google or your small group.

    +

    If you have questions about how any of those exercises worked, use Google.


    @@ -180,9 +142,10 @@ Use a `for` statement to solve each problem. You can do this work in the place t
    -## Check For Understanding +## Additional Practice +This practice work is encouraged, but not required. -[Follow the directions in the README of this GitHub repository](https://github.com/turingschool/m0_fe_for), and submit your fork in the submission form. +[Follow the directions in the README of this GitHub repository](https://github.com/turingschool/m0_fe_for).

    diff --git a/front-end/functions-fasttrack.md b/front-end/functions-fasttrack.md new file mode 100644 index 0000000..0287ea8 --- /dev/null +++ b/front-end/functions-fasttrack.md @@ -0,0 +1,346 @@ +--- +layout: lesson +title: Functions +--- + +## Learning Goals + +- Explain the purpose of functions +- Use built-in methods on appropriate data types +- Define and invoke functions in JavaScript +- Use and explain the flow of data with arguments and parameters +- Describe the purpose of a return value + +## Vocabulary + +- method +- function +- call, invoke +- define, declare +- return value +- parameter +- argument + + + +## Defining Our Own Functions + +Functions are structures in JavaScript that are fundamental to writing a program. A function is essentially a package of instructions for a program to follow. The JavaScript language has many methods built-in that you'll explore later in this lesson. Built-in methods are great and you will use them regularly as a developer. There will also be times when you need to write your own method to solve a unique problem in the application you are building or maintaining. + +### Syntax for _Defining_ a Function + +To define (or declare) a function, the following syntax must be used: +- The `function` keyword declares a new function. +- The function name follows the `function` keyword and is determined by the person writing the code. It's best if the name describes what the function _does_. +- A set of opening and closing parentheses `()`. +- A set of opening and closing curly brackets `{}`, which will create the code block. +- One or more lines of code inside the curly brackets - this is where the "instructions" live. These instructions describe what the function should do when it is called. +- The value that follows the `return` keyword is the data that the function will return when it is called. + +```javascript +function greetATexan() { + return "Howdy, partner!"; +} +``` + +After defining a function, nothing will _appear_ to happen. The interpreter that reads the JavaScript code will read it, and be aware of that set of instructions, but it won't carry out those instructions until it is explicitly told to do so. + +### Syntax for _Calling_ a Function + +To instruct the interpreter to carry out the instructions in a function, the developer must write code to call (or invoke) that function. To call a function, the following syntax must be used: +- The function name +- A set of opening and closing parentheses `()` +- To follow conventions and best practices, the line should end with a semi-colon `;` + +```javascript +greetATexan(); +``` + + +### Naming Conventions + +Since functions provide action to a program, they should be named accordingly; it's best practice to start them with a verb. Like variables, JavaScript functions should use `camelCase` when they involve more than one word and should be written carefully to describe their role specifically without being overly verbose. + +Examples of function names that follow best practices: +- `getUserInput` +- `displayFollowers` +- `addTwoNumbers` +- `findLongestName` + + + +### A Function Metaphor + +Often, we want to use a function to perform an action on or with a piece of data. Think back to those built-in methods. We didn't simply call the `startsWith()` method by itself. We called it on a String object and it returned a Boolean value. We can do the same thing with the functions we define. Think of your function like a machine with inputs and outputs. + + + +If this were a cookie machine, for example, the machine would take in all of the raw ingredients (eggs, flour, sugar, etc.) and perform some steps to make the cookies: +1. Mix ingredients to make dough +2. Place dough balls on a baking sheet +3. Bake at 350 degrees for 10 minutes +4. Let cookies cool +5. Serve the cookies on a plate + +We can imagine that our cookie machine would do all of those steps and then give us back freshly baked, warm cookies! + +Let's expand this example to any kind of machine. We give the machine the raw materials, it does something with those materials, and then returns the final product. This is _very_ similar to what we are doing with our own functions. We can give the function some piece of data or information (or even multiple pieces of information) and then the function does something with that information and spits out a return value. + +
    +

    Waterfall

    +

    Look at the function call below and make a guess about how this might be different from the previous method example.

    +
    +  greetATexan("Kaitlyn");
    +  // => "Howdy, Kaitlyn!"
    +

    Type your answers in the chat and be ready to submit when it's time!

    +
    +
    + +Without possibly having all the information about JavaScript syntax, you probably made some connection as to what might be happening with the previous code snippet. The `greetATexan()` function was called, but this time, we were able to dynamically change the name of the person we were greeting! + +### Arguments and Parameters + +Functions can be more powerful and dynamic when they have additional information about the situation each time they are called. We must follow a specific syntax to "pass information" into a function: +- In the function definition, parameter(s) must be declared. Parameters act like placeholder variables that can be accessed inside the function. As such, variable naming conventions should be followed when naming parameters. +- In the function call, argument(s) - the actual data - must be provided. Since this is actual data, it must be in the form of a valid JavaScript data type, such as a String or Number. +- The number of arguments passed in should match the number of parameters declared. + +```javascript +function greetATexan(name) { + return `Howdy, ${name}!`; +} + +console.log(greetATexan("Kaitlyn")); +// => "Howdy, Kaitlyn!" + +console.log(greetATexan("Brian")); +// => "Howdy, Brian!" +``` + +> **Note:** You'll notice that we are using the `console.log()` statement with the function call this time. This allows us to also **see** the return value of the `greetATexan` function printed to the console, but it is not necessary. The code `greetATexan("Kaitlyn")` by itself does return the string "Howdy, Kaitlyn!", but if we want to see it printed in the console, we will need to use `console.log()` along with the function call. + +The following code snippet illustrates a function definition and call that involves 2 pieces of data, both Numbers. + +```javascript +function subtract(max, min) { + var difference = max - min; + return difference; +} + +console.log(subtract(10, 3)); +// => 7 +``` + +
    +

    Pair Practice

    +

    In your Breakout room, the person with the longest first name will Drive. The other will Navigate. The Driver should screenshare a replit and the Navigator should keep these instructions up.

    +
      +
    • Write a function named greetAnAnimal. This method should declare one parameter, a String, and when called, should return a string with a greeting for the specific animal that was passed in as an argument.
    • +
    • Write a function named multiply. This method should declare two parameters, both Numbers, and when called, should return the product of the two Numbers. Call the method several times with different arguments and run the code to ensure it's working as expected.
    • +
    +
    +
    + + +### Return Values + +It's important to note that JavaScript functions _are not required to have a return value_. The return statement is **optional** in JavaScript functions. As a result, it is entirely possible to write a JavaScript function that only performs a series of actions without returning anything at all. + +```javascript +function makeFreshPesto() { + console.log("Buy ingredients: basil, parmesan, romano, olive oil, pine nuts, garlic, salt, pepper"); + console.log("Pulse basil and pine nuts"); + console.log("Add garlic and cheeses"); + console.log("Slowly pour in oil"); + console.log("Season"); +} + +makeFreshPesto(); +``` + +However, it is often preferable to have our function return a value, because it increases its utility. Let's take a look at an example. + +```javascript +function add(num1, num2) { + var sum = num1 + num2; + console.log(sum); +} + +add(5, 2); +// => 7 +``` + +This `add` function adds the numbers together and logs the sum to the console. This is cool, but what if I wanted to use that number in a _different_ way? The example below shows how I might modify that function, so that it simply `returns` the sum instead of logging the value to the console. Then, I can do all kinds of different things with that return value! In this way, functions that return a value are more flexible than functions that only log to the console. + +```javascript +function add(num1, num2) { + var sum = num1 + num2; + return sum; +} + +console.log(add(5, 2)); +// --> 7 +console.log(`The sum of 5 and 2 is ${add(5, 2)}.`) +// --> "The sum of 5 and 2 is 7." +``` + +>**Key Point:** Up until now, we've used the `console.log()` statement to see values printed to the console. Be careful not to confuse what you see in the console with the return value of the function or method -- these are two different things. We use `console.log()` to **see** data in the console, but what we see in the console is **not always** the return value. + +
    + +### Storing a Return Value + +The examples we've looked at so far call the function and execute the code within the function, but the return values go nowhere/can never be used in the program again. Many times, we'll store the return value of a function in another variable, as modeled below: + +```javascript +function add(num1, num2) { + return num1 + num2; +} + +var sum1 = add(10, 4); +var sum2 = add(7, 20); + +console.log(sum1); +console.log(sum2); +``` + +
    +

    Pair Practice

    +

    In your Breakout room, the person with the shortest first name will Drive. The other will Navigate. The Driver should screenshare a replit and the Navigator should keep these instructions up.

    +
      +
    • Write a function named getAge. This method should declare one parameter, a Number, representing a birth year.
    • +
    • When called, the function should calculate the person's approximate age. Let's not worry about birth month or day. 😉
    • +
    • The function should return a Number representing the person's age.
    • +
    • Call the function several times with different arguments and store the return values in variables.
    • +
    • Print a sentence that says, "You have lived ___ years of life!" with each variable interpolated into the String.
    • +
    +
    + +
    + +
    +

    Key Points Summary

    +
      +
    • A function is a packaged set of directions. If the function is never called, it will never run. And a function can be called many times, if needed!
    • +
    • The number of arguments in a function call must match the number of parameters in the function definition.
    • +
    • Function names should start with a verb and use camelCase.
    • +
    • Return values are optional in JavaScript functions. If a return value is included in a function, that value after the return keyword is the data that will be returned when a function is called.
    • +
    +
    +
    + +## Self-Teach +Part of what you'll experience at Turing is learning a technical topic on your own. Practicing this skill at Turing will get you prepared for the job where you will do this often. + +Take time between now and your next session to self-teach the following section. + + +## Warm-Up for Built-In Methods + +
    +

    Exploration: PART 1

    +

    Fork, then run the code in this replit and observe the output.

    +

    Discuss: How did each line of code, produce each respective line of output? Which parts make sense, and which are confusing?

    +
    +
    + +## Built-In Methods + +Both `methods` and `functions` are sets of instructions that perform a specific task. The only difference is that a method is associated with an object, while a function is not. For now, we'll use the term `method` to describe the pre-packaged functions that are built into the language and are called on a specific data type. The term `function` is used to describe a block of code that a developer designs to perform a particular task. Let's explore some of those built-in `methods` available to us in JavaScript. + +The code snippet below is an example from the previous Exploration activity: + +```javascript +console.log("Hello World".startsWith("H")); +``` + +>To describe the code snippet in English, one could say, "the `startsWith()` method is being called on the string 'Hello World'." Since "Hello World" does start with "H", `true` will be the return value. The `console.log()` command prints that return value of `true` to the console. + +In this particular example, the utility of the `startsWith()` method is to determine if a String starts with a specified character, or not. It answers the question with a Boolean (`true` or `false`). The benefit of having this method built into JavaScript is if a developer needs to check if a String starts with a specific character, they can use the `startsWith()` method anywhere they need to check. If they didn't have a pre-packaged method, they'd have to write several lines of code involving logic, every time they want to check if an integer is odd. **Reusability is what makes methods and functions so powerful.** + +
    +
    +

    Exploration: PART 2

    +

    In the same replit from the first exploration, comment out the code from Part 1, and uncomment the code under Part 2.

    +
      +
    • Run the code.
    • +
    • Discuss: What is different about this from the first set of method calls? How did each line of code, produce each respective line of output? Which parts make sense, and which are confusing?
    • +
    +
    +
    + +The following code snippet demonstrates that a method can be called on a variable assigned to data: + +```javascript +var newString = "Hello World"; +console.log(newString.toUpperCase()); +``` + +>To describe the code snippet in English, one could say, "the first line declares a variable called `newString` and the second line calls the `toUpperCase()` method on the `newString` variable." As a result, the method will return a String object where any letter character in the original String stored in `newString` will now be uppercase. The `console.log()` command prints that return value of `"HELLO WORLD"` to the console. However, it's important to note that the original data stored in `newString` is not modified permanently. + +
    +
    +

    Exploration: PART 3

    +

    In the same replit, comment out the code from Part 2, and uncomment the variable declarations and first method call under Part 3.

    +
      +
    • Run the code and read the error message carefully. Work to make sense of what the problem is.
    • +
    • Comment out that method call, and uncomment the next one. Run the code and read the error message carefully. Work to make sense of what the problem is.
    • +
    • Repeat the previous step until you've run the code for each method call.
    • +
    • Modify the existing code so that it runs without errors.
    • +
    • Write down a 1-3 sentence explanation of your main takeaway from this exploration.
    • +
    +
    +
    + +
    +

    Key Points

    +
      +
    • A method is a package of instructions that once defined, can be reused as many times as needed.
    • +
    • A method can be called on a variable that holds data.
    • +
    • JavaScript provides built-in methods for each data type, but not every method will work on every type of data.
    • +
    +
    +
    + +## Check For Understanding + +- Complete the work in the CFU repository. +- Add a link to your respository under a new section of your Mod 0 Gist called `Functions`. + +
    +
    +
    \ No newline at end of file diff --git a/front-end/objects-fasttrack.md b/front-end/objects-fasttrack.md new file mode 100644 index 0000000..48903b7 --- /dev/null +++ b/front-end/objects-fasttrack.md @@ -0,0 +1,151 @@ +--- +layout: lesson +title: Object Literals +--- + +## Learning Goals + +- Use JavaScript syntax to declare variables that store Object Literals +- Access data from JavaScript Object Literals + +## Vocabulary + +- Object Literal +- key +- key-value pair +- value + +## Warm Up + +Look at the following array and take a moment to consider: What is problematic about it? How would you prefer to structure a list of students and such information? + +```javascript +var students = ["Cristie Soto", "A+", "B", "in progress", true, "Oscar Smith", "A-", "D", "dropped", true]; +``` +
    +
    + +## Object Literals + +Object Literals (Objects) allow us to structure data in a different way than Arrays. It's not better; it's just different. Like an Array, an Object is a data structure used for representing a collection of things. But whereas an Array generally represents a list of ordered, indexed values, **an Object represents a collection of _named_ values**. These names are called keys, and each key has a corresponding value. In an Object, we can insert data by assigning it to a name and later retrieving it using the same name. + +Some languages call their Objects _dictionaries_ for this reason – you look up a word (the label) to retrieve its definition (the data or value with which the label was associated). + +## Object Syntax + +- An object is enclosed in curly braces `{ }`, key-value pairs are separated by commas, and keys and values are separated by a colon. +- Each key in an object must be unique + - If you attempt to have duplicate keys when you first create an object, you won't get any sort of indicator that you've done so, but the only value that will be stored is that of the last value assigned to a duplicate key. + - If you try to add a new key-value pair using a key that already exists, that new key-value pair will overwrite the previous one - _dangerous_. +- Keys and values can be any of any data type: +```javascript +var student1 = { + name: "Christie Soto", + grades: ["A+", "B", "in progress"], + activeStudent: true +} +``` +- Values can be accessed with dot notation: + - `student1.name` returns `"Christie Soto"` + +
    +

    Object or Array?

    +

    For each example, determine if an Object or Array would be more appropriate, and explain why. Share your responses in the Slack small group channel for feedback and discussions.

    +
      +
    • A store's inventory
    • +
    • The contents of a dishwasher
    • +
    • List of all the places you've traveled to
    • +
    • List of birthdays of all students
    • +
    • Names of all dogs at doggie daycare
    • +
    • Virtual address book
    • +
    • Items of clothing in a dresser
    • +
    +
    +
    + +
    +

    Object Syntax Practice

    +

    Complete the following work in a replit or a new JavaScript file in VS Code:

    +
      +
    1. For one of the examples in the previous activity that you selected would be best suited for an Object, declare a variable that stores an Object with some (possibly fake) data.
    2. +
    3. Declare a variable that stores an Object that represents this tweet.
    4. +
    +
    + +## Accessing an Object + +The examples below explore the `suitcase` Object: + +```javascript +var suitcase = { + socks: 4, + jeans: 1 +}; +``` + +Did we put any jackets on our list? Let’s check: +```javascript +suitcase.jackets; +// => undefined +``` + +We can create a new key-value pair: +```javascript +suitcase.shirts = 3; +suitcase.swimsuits = true; +``` + +We can remove the socks: +```javascript +delete suitcase.socks; +``` + +Check on the shirts: +```javascript +suitcase.shirts; +// => 3 +``` + +Let's check what keys are in our Object: +```javascript +Object.keys(suitcase); +// => ["jeans", "shirts", "swimsuit"] +``` + +Let's check what values are in our Object: +```javascript +Object.values(suitcase); +// => [1, 3, true] +``` + +Note that when we use the `Object.keys` and `Object.values` methods, the return value of each is an Array! +
    + +
    +

    Object Syntax and Access Practice

    +

    Use the following zoo variable to complete each prompt:

    +
    +  var zoo = {
    +    giraffes: 3,
    +    zebras: 12,
    +    hippos: 2
    +  };
    +  
    +
      +
    1. Print all of the keys of the zoo Object
    2. +
    3. Print all of the values of the zoo Object
    4. +
    5. Add an animal to the zoo
    6. +
    7. Check how many monkeys are in the zoo
    8. +
    9. Add another animal to the zoo
    10. +
    +
    +
    + +## Additional Practice +This additional practice is encouraged, but not required. + +Complete the work in this repository. + +
    +
    +
    \ No newline at end of file diff --git a/front-end/objects.md b/front-end/objects.md index 626fdcd..244040c 100644 --- a/front-end/objects.md +++ b/front-end/objects.md @@ -70,7 +70,6 @@ var student1 = {
  • For one of the examples in the previous activity that you selected would be best suited for an Object, declare a variable that stores an Object with some (possibly fake) data.
  • Declare a variable that stores an Object that represents this tweet.
  • -

    Take a screenshot or save in this work in a file and be ready to share it in Stand Up tomorrow!

    ## Accessing an Object @@ -135,16 +134,14 @@ Note that when we use the `Object.keys` and `Object.values` methods, the return
    1. Print all of the keys of the zoo Object
    2. Print all of the values of the zoo Object
    3. -
    4. Print the value of the first animal of the zoo
    5. Add an animal to the zoo
    6. Check how many monkeys are in the zoo
    7. Add another animal to the zoo
    8. -
    9. Print all of the keys of the zoo Object

    -## Check For Understanding +## Additional Practice Complete the work in the CFU repository and submit your work using the submission form. diff --git a/shared/asking_qs.md b/shared/asking_qs.md index 7d5bb00..e1a45d4 100644 --- a/shared/asking_qs.md +++ b/shared/asking_qs.md @@ -30,7 +30,7 @@ Information to include in every question: 1. What happened instead? 1. What have you attempted/googled/read to find a solution? -Your goal is probably to get an answer ASAP, and a secondary goal should be to document this issue/challenge to help someone who may encounter the same thing in the future. Formatting your question well supports both of these goals. Some things to consider: +Your goal is probably to get an answer ASAP, and a secondary goal should be to document this issue/challenge to help someone who may encounter the same thing in the future (including _your_ future self!). Formatting your question well supports both of these goals. Some things to consider: - Code snippets should not be formatted as plain text. Very short snippets should be formatted as `inline code` and ... ``` longer snippets @@ -76,7 +76,11 @@ As you prepare to ask questions—in written form or in live communications—** ## Check For Understanding -There is nothing to submit for this assignment, but we do expect you to follow these best practices moving forward! Come back to this lesson when you need a reminder of how to ask excellent technical questions or keep a sticky note on your desk with the 4 best practices - whatever it takes to build a strong habit for yourself! +In your Mod 0 Gist, please create a section called `Asking Technical Questions` and answer the following questions: + +1. What are the steps you will take when asking a technical question? +1. We lay out these steps in a particular order. What do you think the reasoning behind this might be? +1. How will you refer back to this question-asking strategy while in Mods 1 and beyond? (ex: add these steps to your notes, write them on a sticky note, etc.)

    diff --git a/shared/dtr.md b/shared/dtr.md index da9378a..46ded84 100644 --- a/shared/dtr.md +++ b/shared/dtr.md @@ -20,7 +20,7 @@ You will be a contributor in several paired and group projects working on comple Before every project kickoff, we ask students to participate in a exercise known as **Defining the Relationship (DTR)**, where you will work to set realistic expectations with your teammates around workflow, communication, etc. -However, prior starting Mod 1, it is crucial for you to reflect on what works for YOU! Obviously, this will change over the course of your Turing career as you learn more about your strengths and weaknesses, which is why this is helpful to think of as a living document. +Prior to starting Mod 1, it is crucial for you to reflect on what works for YOU! Obviously, this will change over the course of your Turing career as you learn more about your strengths and working styles, which is why this is helpful to think of as a living document. ### Words of Wisdom @@ -33,9 +33,18 @@ As you work through this document, avoid the following pitfalls: ## Preparing to DTR -You will learn a lot in between now and the first paired project you are assigned in Mod 1 - technical concepts, about yourself, and what working on technical projects collaboratively can look and feel like. +Create a section in your Mod 0 Gist entitled `DTR` and add these questions as well as your responses. -Start preparing for your first DTR conversation with a future project partner by following the directions in this Gist and be prepared to share your reflections with your small group in your next session. +Guiding Questions +For this initial exploration into what you bring to a team, try to avoid thinking about your technical skills. Your answers to these questions should apply to any project/team that you work on: + +1. How would you describe your preferred working style? (Alone,in groups, etc.) +1. What strengths do you bring to a team? +1. What’s gone well or poorly in your previous group project settings? What can you do to either ensure those best practices carry over into projects here or to avoid common pitfalls that might come up? +1. How do you prefer to handle disagreements that come up? (Yes, they will come up!) +1. How do you communicate best? What tools do you need to communicate well with your teammates? +1. How do you prefer to receive feedback? How do you prefer to give feedback? +1. What scheduling constraints do you have? What are your preferred work times outside of normal school hours?

    \ No newline at end of file diff --git a/shared/final-reflections.md b/shared/final-reflections.md new file mode 100644 index 0000000..4de254d --- /dev/null +++ b/shared/final-reflections.md @@ -0,0 +1,17 @@ +--- +layout: lesson +title: Final Reflections +--- + +It’s time to take a moment and reflect on all of your hard work and progress throughout the week. Please create a section in your Mod 0 Gist entitled `Final Reflections` and answer the below reflection questions. + +**Reflection Questions:** +- As you look back on your time in Mod 0, what are you most proud of? +- What did you learn about yourself, as a person or a student, during Mod 0? +- What is one thing you want to remember as you start this new journey to become a software developer at Turing? +- Finally, share some gratitude for the people who were most supportive to you throughout this Mod 0 experience! + + +
    +
    +
    \ No newline at end of file diff --git a/shared/git.md b/shared/git.md index 90c15c9..4dc7dc8 100644 --- a/shared/git.md +++ b/shared/git.md @@ -58,13 +58,19 @@ Stop at the provided prompts to take notes and complete practice exercises as in
    + +## Check For Understanding + +Please respond to the following questions by adding them to your Mod 0 Gist in a section entitled **Git Workflow** + +1. How confident do you feel in your understanding and fluency with the Git workflow? +1. What do you still need to practice or learn? How will you do that? +1. What part of the Git Workflow is still confusing for you? + ## Additional Resources (Optional) - Read this article on Git commit messages - What's the use of the staging area in Git? on Stack Overflow -## Check For Understanding - -Follow the directions in this Gist and submit your fork of it in the submission form.

    diff --git a/shared/github.md b/shared/github.md index 74d87c2..4134c90 100644 --- a/shared/github.md +++ b/shared/github.md @@ -37,8 +37,6 @@ Before we dive into creating GitHub repositories, let's take a moment to get com
  • Who is the user that created and owns this repository?
  • How many commits are on this repo?
  • When was the last commit made?
  • -
  • Find 2 commit messages that do not follow conventions - write them down, and write down a better commit message to replace each.
  • -
  • How many times has this repository been forked?

  • @@ -54,7 +52,7 @@ There are many ways to create and connect local (on y 1. **Before completing the next steps, make sure that you have the `SSH` button selected at the top.** Then, follow the directions under `...or push an existing repository from the command line`, by running the following commands: - `git remote add origin git@github.com:USERNAME/REPO_NAME.git` This command tells the local repository to set the remote repository to this address. We refer to it as the `origin`. - _`git branch -M main` You do not need to do this if you have already configured Git to name the default branch `main`._ - - `git push -u origin main` This sends the current version of the project up to the remote repository, and sets the `main` branch as the default branch to send work up to. + - `git push -u origin main` This sends the current version of the project up to the remote repository, and sets the `main` branch as the default branch to send work up to. Side note, the `-u` is optional. 1. Refresh your GitHub browser tab. You should now see your repository!
    @@ -75,7 +73,7 @@ Now that we have our local repository connected to a remote repository, we can s git push ``` -Since we used the `-u origin main` in our original push to connect the two repos, we already established main as the upstream branch. For subsequent pushes, we can take out that part of the command and simply use git push. +Since we used the `-u origin main` in our original push to connect the two repos, we already established main as the upstream branch. For subsequent pushes, we can take out that part of the command and simply use git push. _Note:_ If you did not use `-u` to set the upstream, you'll simply type `git push origin main` every time. After running this command, Git will send your work up to GitHub (you must be connected to the internet), and you'll get many lines of output, finally telling you the work was successfully sent up. Refresh your GitHub browser tab, and the changes will be available there. Pushing work up to a repository is the act of using Git commands to send the most recent commits on a local repository up to the remote repository. @@ -152,7 +150,7 @@ To fork and clone a pre-existing GitHub repository, follow the steps below.

    Work through this prompt independently.